2024.8.23
Loading...
Searching...
No Matches
BinMariadb Class Reference
+ Inheritance diagram for BinMariadb:
+ Collaboration diagram for BinMariadb:

Public Member Functions

 __construct ($id, $type)
 
 changePort ($port, $checkUsed=false, $wbProgressBar=null)
 
 changeRootPassword ($currentPwd, $newPwd, $wbProgressBar=null)
 
 checkPort ($port, $showWindow=false)
 
 checkRootPassword ($currentPwd=null, $wbProgressBar=null)
 
 getAdmin ()
 
 getCliExe ()
 
 getCmdLineOutput ($cmd)
 
 getConf ()
 
 getErrorLog ()
 
 getExe ()
 
 getPort ()
 
 getRootPwd ()
 
 getRootUser ()
 
 getService ()
 
 reload ($id=null, $type=null)
 
 setEnable ($enabled, $showWindow=false)
 
 setPort ($port)
 
 setRootPwd ($rootPwd)
 
 setRootUser ($rootUser)
 
 setVersion ($version)
 
 switchVersion ($version, $showWindow=false)
 
- Public Member Functions inherited from Module
 __toString ()
 
 getCurrentPath ()
 
 getId ()
 
 getName ()
 
 getRelease ()
 
 getRootPath ()
 
 getSymlinkPath ()
 
 getType ()
 
 getVersion ()
 
 getVersionList ()
 
 isEnable ()
 
 update ($sub=0, $showWindow=false)
 

Data Fields

const CMD_SYNTAX_CHECK = '--help --verbose 1>NUL'
 
const CMD_VARIABLES = 'variables'
 
const CMD_VERSION = '--version'
 
const LOCAL_CFG_ADMIN = 'mariadbAdmin'
 
const LOCAL_CFG_CLI_EXE = 'mariadbCliExe'
 
const LOCAL_CFG_CONF = 'mariadbConf'
 
const LOCAL_CFG_EXE = 'mariadbExe'
 
const LOCAL_CFG_PORT = 'mariadbPort'
 
const LOCAL_CFG_ROOT_PWD = 'mariadbRootPwd'
 
const LOCAL_CFG_ROOT_USER = 'mariadbRootUser'
 
const ROOT_CFG_ENABLE = 'mariadbEnable'
 
const ROOT_CFG_VERSION = 'mariadbVersion'
 
const SERVICE_NAME = 'bearsamppmariadb'
 
- Data Fields inherited from Module
const BUNDLE_RELEASE = 'bundleRelease'
 

Protected Member Functions

 replaceAll ($params)
 
 updateConfig ($version=null, $sub=0, $showWindow=false)
 
- Protected Member Functions inherited from Module
 __construct ()
 
 replace ($key, $value)
 

Private Attributes

 $admin
 
 $cliExe
 
 $conf
 
 $errorLog
 
 $exe
 
 $port
 
 $rootPwd
 
 $rootUser
 
 $service
 

Additional Inherited Members

- Protected Attributes inherited from Module
 $bearsamppConf
 
 $bearsamppConfRaw
 
 $currentPath
 
 $enable
 
 $name
 
 $release = 'N/A'
 
 $rootPath
 
 $symlinkPath
 
 $version
 

Detailed Description

Class BinMariadb

This class represents the MariaDB module in the Bearsampp application. It handles the configuration, management, and operations related to MariaDB.

Definition at line 16 of file class.bin.mariadb.php.

Constructor & Destructor Documentation

◆ __construct()

BinMariadb::__construct ( $id,
$type )

Constructs a BinMariadb object and initializes the module.

Parameters
string$idThe ID of the module.
string$typeThe type of the module.

Definition at line 52 of file class.bin.mariadb.php.

53 {
54 Util::logInitClass( $this );
55 $this->reload( $id, $type );
56 }
reload($id=null, $type=null)
static logInitClass($classInstance)

References Module\$id, Module\$type, Util\logInitClass(), and reload().

Member Function Documentation

◆ changePort()

BinMariadb::changePort ( $port,
$checkUsed = false,
$wbProgressBar = null )

Changes the port for MariaDB.

Parameters
int$portThe new port number.
bool$checkUsedWhether to check if the port is already in use.
mixed$wbProgressBarThe progress bar object for UI updates.
Returns
bool|string True if the port was changed successfully, or the process using the port if it is in use.

Definition at line 182 of file class.bin.mariadb.php.

183 {
184 global $bearsamppWinbinder;
185
186 if ( !Util::isValidPort( $port ) ) {
187 Util::logError( $this->getName() . ' port not valid: ' . $port );
188
189 return false;
190 }
191
192 $port = intval( $port );
193 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
194
195 $isPortInUse = Util::isPortInUse( $port );
196 if ( !$checkUsed || $isPortInUse === false ) {
197 // bearsampp.conf
198 $this->setPort( $port );
199 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
200
201 // conf
202 $this->update();
203 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
204
205 return true;
206 }
207
208 Util::logDebug( $this->getName() . ' port in used: ' . $port . ' - ' . $isPortInUse );
209
210 return $isPortInUse;
211 }
update($sub=0, $showWindow=false)
static logError($data, $file=null)
static isValidPort($port)
static logDebug($data, $file=null)
static isPortInUse($port)

References $port, Module\getName(), Util\isPortInUse(), Util\isValidPort(), Util\logDebug(), Util\logError(), setPort(), and Module\update().

◆ changeRootPassword()

BinMariadb::changeRootPassword ( $currentPwd,
$newPwd,
$wbProgressBar = null )

Changes the root password for MariaDB.

Parameters
string$currentPwdThe current root password.
string$newPwdThe new root password.
mixed$wbProgressBarThe progress bar object for UI updates.
Returns
bool|string True if the password was changed successfully, or an error message if it failed.

Definition at line 313 of file class.bin.mariadb.php.

314 {
315 global $bearsamppWinbinder;
316 $error = null;
317
318 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
319 if ( version_compare( phpversion(), '5.3' ) === -1 ) {
320 $dbLink = @mysqli_connect( '127.0.0.1', $this->rootUser, $currentPwd, '', $this->port );
321 }
322 else {
323 $dbLink = @mysqli_connect( '127.0.0.1:' . $this->port, $this->rootUser, $currentPwd );
324 }
325 if ( !$dbLink ) {
326 $error = mysqli_connect_error();
327 }
328
329 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
330 $stmt = @mysqli_prepare( $dbLink, 'UPDATE mysql.user SET Password=PASSWORD(?) WHERE User=?' );
331 if ( empty( $error ) && $stmt === false ) {
332 $error = mysqli_error( $dbLink );
333 }
334
335 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
336 if ( empty( $error ) && !@mysqli_stmt_bind_param( $stmt, 'ss', $newPwd, $this->rootUser ) ) {
337 $error = mysqli_stmt_error( $stmt );
338 }
339
340 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
341 if ( empty( $error ) && !@mysqli_stmt_execute( $stmt ) ) {
342 $error = mysqli_stmt_error( $stmt );
343 }
344
345 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
346 if ( $stmt !== false ) {
347 mysqli_stmt_close( $stmt );
348 }
349
350 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
351 if ( empty( $error ) && @mysqli_query( $dbLink, 'FLUSH PRIVILEGES' ) === false ) {
352 $error = mysqli_error( $dbLink );
353 }
354
355 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
356 if ( $dbLink ) {
357 mysqli_close( $dbLink );
358 }
359
360 if ( !empty( $error ) ) {
361 return $error;
362 }
363
364 // bearsampp.conf
365 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
366 $this->setRootPwd( $newPwd );
367
368 // conf
369 $this->update();
370 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
371
372 return true;
373 }
setRootPwd($rootPwd)

References setRootPwd(), and Module\update().

◆ checkPort()

BinMariadb::checkPort ( $port,
$showWindow = false )

Checks if the specified port is used by MariaDB.

Parameters
int$portThe port number to check.
bool$showWindowWhether to show a window with the result.
Returns
bool True if the port is used by MariaDB, false otherwise.

Definition at line 221 of file class.bin.mariadb.php.

222 {
223 global $bearsamppLang, $bearsamppWinbinder;
224 $boxTitle = sprintf( $bearsamppLang->getValue( Lang::CHECK_PORT_TITLE ), $this->getName(), $port );
225
226 if ( !Util::isValidPort( $port ) ) {
227 Util::logError( $this->getName() . ' port not valid: ' . $port );
228
229 return false;
230 }
231
232 $fp = @fsockopen( '127.0.0.1', $port, $errno, $errstr, 5 );
233 if ( $fp ) {
234 if ( version_compare( phpversion(), '5.3' ) === -1 ) {
235 $dbLink = mysqli_connect( '127.0.0.1', $this->rootUser, $this->rootPwd, '', $port );
236 }
237 else {
238 $dbLink = mysqli_connect( '127.0.0.1:' . $port, $this->rootUser, $this->rootPwd );
239 }
240 $isMariadb = false;
241 $version = false;
242
243 if ( $dbLink ) {
244 $result = mysqli_query( $dbLink, 'SHOW VARIABLES' );
245 if ( $result ) {
246 while ( false !== ($row = mysqli_fetch_array( $result, MYSQLI_NUM )) ) {
247 if ( $row[0] == 'version' ) {
248 $version = explode( '-', $row[1] );
249 $version = count( $version ) > 1 ? $version[0] : $row[1];
250 }
251 if ( $row[0] == 'version_comment' && Util::startWith( strtolower( $row[1] ), 'mariadb' ) ) {
252 $isMariadb = true;
253 }
254 if ( $isMariadb && $version !== false ) {
255 break;
256 }
257 }
258 if ( !$isMariadb ) {
259 Util::logDebug( $this->getName() . ' port used by another DBMS: ' . $port );
260 if ( $showWindow ) {
261 $bearsamppWinbinder->messageBoxWarning(
263 $boxTitle
264 );
265 }
266 }
267 else {
268 Util::logDebug( $this->getName() . ' port ' . $port . ' is used by: ' . $this->getName() . ' ' . $version );
269 if ( $showWindow ) {
270 $bearsamppWinbinder->messageBoxInfo(
271 sprintf( $bearsamppLang->getValue( Lang::PORT_USED_BY ), $port, $this->getName() . ' ' . $version ),
272 $boxTitle
273 );
274 }
275
276 return true;
277 }
278 }
279 mysqli_close( $dbLink );
280 }
281 else {
282 Util::logDebug( $this->getName() . ' port ' . $port . ' is used by another application' );
283 if ( $showWindow ) {
284 $bearsamppWinbinder->messageBoxWarning(
285 sprintf( $bearsamppLang->getValue( Lang::PORT_NOT_USED_BY ), $port ),
286 $boxTitle
287 );
288 }
289 }
290 }
291 else {
292 Util::logDebug( $this->getName() . ' port ' . $port . ' is not used' );
293 if ( $showWindow ) {
294 $bearsamppWinbinder->messageBoxError(
295 sprintf( $bearsamppLang->getValue( Lang::PORT_NOT_USED ), $port ),
296 $boxTitle
297 );
298 }
299 }
300
301 return false;
302 }
$result
global $bearsamppLang
const PORT_NOT_USED_BY
const PORT_USED_BY_ANOTHER_DBMS
const CHECK_PORT_TITLE
const PORT_USED_BY
const PORT_NOT_USED
static startWith($string, $search)

References $bearsamppLang, $port, $result, Module\$version, Lang\CHECK_PORT_TITLE, Module\getName(), Util\isValidPort(), Util\logDebug(), Util\logError(), Lang\PORT_NOT_USED, Lang\PORT_NOT_USED_BY, Lang\PORT_USED_BY, Lang\PORT_USED_BY_ANOTHER_DBMS, and Util\startWith().

◆ checkRootPassword()

BinMariadb::checkRootPassword ( $currentPwd = null,
$wbProgressBar = null )

Checks if the provided root password is correct.

Parameters
string | null$currentPwdThe current root password. If null, the stored root password is used.
mixed$wbProgressBarThe progress bar object for UI updates.
Returns
bool|string True if the password is correct, or an error message if it is incorrect.

Definition at line 383 of file class.bin.mariadb.php.

384 {
385 global $bearsamppWinbinder;
386 $currentPwd = $currentPwd == null ? $this->rootPwd : $currentPwd;
387 $error = null;
388
389 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
390 if ( version_compare( phpversion(), '5.3' ) === -1 ) {
391 $dbLink = @mysqli_connect( '127.0.0.1', $this->rootUser, $currentPwd, '', $this->port );
392 }
393 else {
394 $dbLink = @mysqli_connect( '127.0.0.1:' . $this->port, $this->rootUser, $currentPwd );
395 }
396 if ( !$dbLink ) {
397 $error = mysqli_connect_error();
398 }
399
400 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
401 if ( $dbLink ) {
402 mysqli_close( $dbLink );
403 }
404
405 if ( !empty( $error ) ) {
406 return $error;
407 }
408
409 return true;
410 }

◆ getAdmin()

BinMariadb::getAdmin ( )

Retrieves the admin executable path for the module.

Returns
string The admin executable path.

Definition at line 680 of file class.bin.mariadb.php.

680 {
681 return $this->admin;
682}}

References $admin.

Referenced by getCmdLineOutput().

+ Here is the caller graph for this function:

◆ getCliExe()

BinMariadb::getCliExe ( )

Retrieves the CLI executable path for the module.

Returns
string The CLI executable path.

Definition at line 671 of file class.bin.mariadb.php.

671 {
672 return $this->cliExe;
673}

References $cliExe.

◆ getCmdLineOutput()

BinMariadb::getCmdLineOutput ( $cmd)

Retrieves the command line output for a given command.

Parameters
string$cmdThe command to execute.
Returns
array An associative array containing:
  • 'syntaxOk' (bool): Whether the command executed without syntax errors.
  • 'content' (string|null): The output content of the command.

Definition at line 498 of file class.bin.mariadb.php.

498 {
499 $result = array(
500 'syntaxOk' => false,
501 'content' => null,
502 );
503
504 $bin = $this->getExe();
505 $removeLines = 0;
506 $outputFrom = '';
507 if ($cmd == self::CMD_SYNTAX_CHECK) {
508 $outputFrom = '2';
509 } elseif ($cmd == self::CMD_VARIABLES) {
510 $bin = $this->getAdmin();
511 $cmd .= ' --user=' . $this->getRootUser();
512 if ($this->getRootPwd()) {
513 $cmd .= ' --password=' . $this->getRootPwd();
514 }
515 $removeLines = 2;
516 }
517
518 if (file_exists($bin)) {
519 $tmpResult = Batch::exec('mariadbGetCmdLineOutput', '"' . $bin . '" ' . $cmd . ' ' . $outputFrom, 5);
520 if ($tmpResult !== false && is_array($tmpResult)) {
521 $result['syntaxOk'] = empty($tmpResult) || !Util::contains(trim($tmpResult[count($tmpResult) - 1]), '[ERROR]');
522 for ($i = 0; $i < $removeLines; $i++) {
523 unset($tmpResult[$i]);
524 }
525 $result['content'] = trim(str_replace($bin, '', implode(PHP_EOL, $tmpResult)));
526 }
527 }
528
529 return $result;
530}
static exec($basename, $content, $timeout=true, $catchOutput=true, $standalone=false, $silent=true, $rebuild=true)
static contains($string, $search)

References $result, Util\contains(), Batch\exec(), getAdmin(), getExe(), getRootPwd(), and getRootUser().

◆ getConf()

BinMariadb::getConf ( )

Retrieves the configuration file path for the module.

Returns
string The configuration file path.

Definition at line 608 of file class.bin.mariadb.php.

608 {
609 return $this->conf;
610}

References $conf.

Referenced by updateConfig().

+ Here is the caller graph for this function:

◆ getErrorLog()

BinMariadb::getErrorLog ( )

Retrieves the error log path for the module.

Returns
string The error log path.

Definition at line 590 of file class.bin.mariadb.php.

590 {
591 return $this->errorLog;
592}

References $errorLog.

◆ getExe()

BinMariadb::getExe ( )

Retrieves the executable path for the module.

Returns
string The executable path.

Definition at line 599 of file class.bin.mariadb.php.

599 {
600 return $this->exe;
601}

References $exe.

Referenced by getCmdLineOutput().

+ Here is the caller graph for this function:

◆ getPort()

BinMariadb::getPort ( )

Retrieves the port number for the module.

Returns
int The port number.

Definition at line 617 of file class.bin.mariadb.php.

617 {
618 return $this->port;
619}

References $port.

◆ getRootPwd()

BinMariadb::getRootPwd ( )

Retrieves the root password for the module.

Returns
string The root password.

Definition at line 653 of file class.bin.mariadb.php.

653 {
654 return $this->rootPwd;
655}

References $rootPwd.

Referenced by getCmdLineOutput().

+ Here is the caller graph for this function:

◆ getRootUser()

BinMariadb::getRootUser ( )

Retrieves the root user for the module.

Returns
string The root user.

Definition at line 635 of file class.bin.mariadb.php.

635 {
636 return $this->rootUser;
637}

References $rootUser.

Referenced by getCmdLineOutput().

+ Here is the caller graph for this function:

◆ getService()

BinMariadb::getService ( )

Retrieves the service associated with the module.

Returns
Win32Service The service object.

Definition at line 549 of file class.bin.mariadb.php.

549 {
550 return $this->service;
551}

References $service.

◆ reload()

BinMariadb::reload ( $id = null,
$type = null )

Reloads the module configuration based on the provided ID and type.

Parameters
string | null$idThe ID of the module. If null, the current ID is used.
string | null$typeThe type of the module. If null, the current type is used.

Reimplemented from Module.

Definition at line 64 of file class.bin.mariadb.php.

65 {
67 Util::logReloadClass( $this );
68
69 $this->name = $bearsamppLang->getValue( Lang::MARIADB );
70 $this->version = $bearsamppConfig->getRaw( self::ROOT_CFG_VERSION );
71 parent::reload( $id, $type );
72
73 $this->enable = $this->enable && $bearsamppConfig->getRaw( self::ROOT_CFG_ENABLE );
74 $this->service = new Win32Service( self::SERVICE_NAME );
75 $this->errorLog = $bearsamppRoot->getLogsPath() . '/mariadb.log';
76
77 if ( $this->bearsamppConfRaw !== false ) {
78 $this->exe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_EXE];
79 $this->conf = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CONF];
80 $this->port = $this->bearsamppConfRaw[self::LOCAL_CFG_PORT];
81 $this->rootUser = isset( $this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_USER] ) ? $this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_USER] : 'root';
82 $this->rootPwd = isset( $this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_PWD] ) ? $this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_PWD] : '';
83 $this->cliExe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CLI_EXE];
84 $this->admin = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_ADMIN];
85 }
86
87 if ( !$this->enable ) {
88 Util::logInfo( $this->name . ' is not enabled!' );
89
90 return;
91 }
92 if ( !is_dir( $this->currentPath ) ) {
93 Util::logError( sprintf( $bearsamppLang->getValue( Lang::ERROR_FILE_NOT_FOUND ), $this->name . ' ' . $this->version, $this->currentPath ) );
94
95 return;
96 }
97 if ( !is_dir( $this->symlinkPath ) ) {
98 Util::logError( sprintf( $bearsamppLang->getValue( Lang::ERROR_FILE_NOT_FOUND ), $this->name . ' ' . $this->version, $this->symlinkPath ) );
99
100 return;
101 }
102 if ( !is_file( $this->bearsamppConf ) ) {
103 Util::logError( sprintf( $bearsamppLang->getValue( Lang::ERROR_CONF_NOT_FOUND ), $this->name . ' ' . $this->version, $this->bearsamppConf ) );
104
105 return;
106 }
107 if ( !is_file( $this->exe ) ) {
108 Util::logError( sprintf( $bearsamppLang->getValue( Lang::ERROR_EXE_NOT_FOUND ), $this->name . ' ' . $this->version, $this->exe ) );
109
110 return;
111 }
112 if ( !is_file( $this->conf ) ) {
113 Util::logError( sprintf( $bearsamppLang->getValue( Lang::ERROR_CONF_NOT_FOUND ), $this->name . ' ' . $this->version, $this->conf ) );
114
115 return;
116 }
117 if ( !is_numeric( $this->port ) || $this->port <= 0 ) {
118 Util::logError( sprintf( $bearsamppLang->getValue( Lang::ERROR_INVALID_PARAMETER ), self::LOCAL_CFG_PORT, $this->port ) );
119
120 return;
121 }
122 if ( empty( $this->rootUser ) ) {
123 Util::logError( sprintf( $bearsamppLang->getValue( Lang::ERROR_INVALID_PARAMETER ), self::LOCAL_CFG_ROOT_USER, $this->rootUser ) );
124
125 return;
126 }
127 if ( !is_file( $this->cliExe ) ) {
128 Util::logError( sprintf( $bearsamppLang->getValue( Lang::ERROR_EXE_NOT_FOUND ), $this->name . ' ' . $this->version, $this->cliExe ) );
129
130 return;
131 }
132 if ( !is_file( $this->admin ) ) {
133 Util::logError( sprintf( $bearsamppLang->getValue( Lang::ERROR_EXE_NOT_FOUND ), $this->name . ' ' . $this->version, $this->admin ) );
134
135 return;
136 }
137
138 $this->service->setDisplayName( APP_TITLE . ' ' . $this->getName() );
139 $this->service->setBinPath( $this->exe );
140 $this->service->setParams( self::SERVICE_NAME );
141 $this->service->setStartType( Win32Service::SERVICE_DEMAND_START );
142 $this->service->setErrorControl( Win32Service::SERVER_ERROR_NORMAL );
143 }
global $bearsamppRoot
const LOCAL_CFG_ROOT_USER
const ERROR_FILE_NOT_FOUND
const MARIADB
const ERROR_INVALID_PARAMETER
const ERROR_CONF_NOT_FOUND
const ERROR_EXE_NOT_FOUND
static logReloadClass($classInstance)
static logInfo($data, $file=null)
global $bearsamppConfig
Definition homepage.php:26
const APP_TITLE
Definition root.php:12

References $bearsamppConfig, $bearsamppLang, $bearsamppRoot, Module\$id, Module\$type, APP_TITLE, Lang\ERROR_CONF_NOT_FOUND, Lang\ERROR_EXE_NOT_FOUND, Lang\ERROR_FILE_NOT_FOUND, Lang\ERROR_INVALID_PARAMETER, Module\getName(), LOCAL_CFG_ADMIN, LOCAL_CFG_CLI_EXE, LOCAL_CFG_CONF, LOCAL_CFG_EXE, LOCAL_CFG_PORT, LOCAL_CFG_ROOT_PWD, LOCAL_CFG_ROOT_USER, Util\logError(), Util\logInfo(), Util\logReloadClass(), Lang\MARIADB, Win32Service\SERVER_ERROR_NORMAL, and Win32Service\SERVICE_DEMAND_START.

Referenced by __construct(), setEnable(), and setVersion().

+ Here is the caller graph for this function:

◆ replaceAll()

BinMariadb::replaceAll ( $params)
protected

Replaces multiple key-value pairs in the configuration file.

Parameters
array$paramsAn associative array of key-value pairs to replace.

Reimplemented from Module.

Definition at line 150 of file class.bin.mariadb.php.

151 {
152 $content = file_get_contents( $this->bearsamppConf );
153
154 foreach ( $params as $key => $value ) {
155 $content = preg_replace( '|' . $key . ' = .*|', $key . ' = ' . '"' . $value . '"', $content );
156 $this->bearsamppConfRaw[$key] = $value;
157 switch ( $key ) {
159 $this->port = $value;
160 break;
162 $this->rootUser = $value;
163 break;
165 $this->rootPwd = $value;
166 break;
167 }
168 }
169
170 file_put_contents( $this->bearsamppConf, $content );
171 }

References LOCAL_CFG_PORT, LOCAL_CFG_ROOT_PWD, and LOCAL_CFG_ROOT_USER.

◆ setEnable()

BinMariadb::setEnable ( $enabled,
$showWindow = false )

Enables or disables the module.

Parameters
bool$enabledWhether to enable or disable the module.
bool$showWindowWhether to show a window with the result.

Definition at line 559 of file class.bin.mariadb.php.

559 {
560 global $bearsamppConfig, $bearsamppLang, $bearsamppWinbinder;
561
562 if ($enabled == Config::ENABLED && !is_dir($this->currentPath)) {
563 Util::logDebug($this->getName() . ' cannot be enabled because bundle ' . $this->getVersion() . ' does not exist in ' . $this->currentPath);
564 if ($showWindow) {
565 $bearsamppWinbinder->messageBoxError(
566 sprintf($bearsamppLang->getValue(Lang::ENABLE_BUNDLE_NOT_EXIST), $this->getName(), $this->getVersion(), $this->currentPath),
567 sprintf($bearsamppLang->getValue(Lang::ENABLE_TITLE), $this->getName())
568 );
569 }
570 $enabled = Config::DISABLED;
571 }
572
573 Util::logInfo($this->getName() . ' switched to ' . ($enabled == Config::ENABLED ? 'enabled' : 'disabled'));
574 $this->enable = $enabled == Config::ENABLED;
575 $bearsamppConfig->replace(self::ROOT_CFG_ENABLE, $enabled);
576
577 $this->reload();
578 if ($this->enable) {
579 Util::installService($this, $this->port, self::CMD_SYNTAX_CHECK, $showWindow);
580 } else {
581 Util::removeService($this->service, $this->name);
582 }
583}
const DISABLED
const ENABLED
const ENABLE_TITLE
const ENABLE_BUNDLE_NOT_EXIST
static installService($bin, $port, $syntaxCheckCmd, $showWindow=false)
static removeService($service, $name)

References $bearsamppConfig, $bearsamppLang, Config\DISABLED, Lang\ENABLE_BUNDLE_NOT_EXIST, Lang\ENABLE_TITLE, Config\ENABLED, Module\getName(), Module\getVersion(), Util\installService(), Util\logDebug(), Util\logInfo(), reload(), and Util\removeService().

◆ setPort()

BinMariadb::setPort ( $port)

Sets the port number for the module.

Parameters
int$portThe port number to set.

Definition at line 626 of file class.bin.mariadb.php.

626 {
627 $this->replace(self::LOCAL_CFG_PORT, $port);
628}
replace($key, $value)

References $port, and Module\replace().

Referenced by changePort().

+ Here is the caller graph for this function:

◆ setRootPwd()

BinMariadb::setRootPwd ( $rootPwd)

Sets the root password for the module.

Parameters
string$rootPwdThe root password to set.

Definition at line 662 of file class.bin.mariadb.php.

662 {
663 $this->replace(self::LOCAL_CFG_ROOT_PWD, $rootPwd);
664}

References $rootPwd, and Module\replace().

Referenced by changeRootPassword().

+ Here is the caller graph for this function:

◆ setRootUser()

BinMariadb::setRootUser ( $rootUser)

Sets the root user for the module.

Parameters
string$rootUserThe root user to set.

Definition at line 644 of file class.bin.mariadb.php.

644 {
645 $this->replace(self::LOCAL_CFG_ROOT_USER, $rootUser);
646}

References $rootUser, and Module\replace().

◆ setVersion()

BinMariadb::setVersion ( $version)

Sets the version of the module.

Parameters
string$versionThe version to set.

Reimplemented from Module.

Definition at line 537 of file class.bin.mariadb.php.

537 {
538 global $bearsamppConfig;
539 $this->version = $version;
540 $bearsamppConfig->replace(self::ROOT_CFG_VERSION, $version);
541 $this->reload();
542}

References $bearsamppConfig, Module\$version, and reload().

Referenced by updateConfig().

+ Here is the caller graph for this function:

◆ switchVersion()

BinMariadb::switchVersion ( $version,
$showWindow = false )

Switches the version of MariaDB.

Parameters
string$versionThe version to switch to.
bool$showWindowWhether to show a window with the result.
Returns
bool True if the version was switched successfully, false otherwise.

Definition at line 420 of file class.bin.mariadb.php.

421 {
422 Util::logDebug( 'Switch ' . $this->name . ' version to ' . $version );
423
424 return $this->updateConfig( $version, 0, $showWindow );
425 }
updateConfig($version=null, $sub=0, $showWindow=false)

References Module\$version, Util\logDebug(), and updateConfig().

◆ updateConfig()

BinMariadb::updateConfig ( $version = null,
$sub = 0,
$showWindow = false )
protected

Updates the configuration for the specified version.

Parameters
string | null$versionThe version to update to. If null, the current version is used.
int$subThe sub-level for logging indentation.
bool$showWindowWhether to show a window with the result.
Returns
bool True if the configuration was updated successfully, false otherwise.

Reimplemented from Module.

Definition at line 436 of file class.bin.mariadb.php.

436 {
437 global $bearsamppLang, $bearsamppApps, $bearsamppWinbinder;
438
439 if (!$this->enable) {
440 return true;
441 }
442
443 $version = $version == null ? $this->version : $version;
444 Util::logDebug(($sub > 0 ? str_repeat(' ', 2 * $sub) : '') . 'Update ' . $this->name . ' ' . $version . ' config');
445
446 $boxTitle = sprintf($bearsamppLang->getValue(Lang::SWITCH_VERSION_TITLE), $this->getName(), $version);
447
448 $conf = str_replace('mariadb' . $this->getVersion(), 'mariadb' . $version, $this->getConf());
449 $bearsamppConf = str_replace('mariadb' . $this->getVersion(), 'mariadb' . $version, $this->bearsamppConf);
450
451 if (!file_exists($conf) || !file_exists($bearsamppConf)) {
452 Util::logError('bearsampp config files not found for ' . $this->getName() . ' ' . $version);
453 if ($showWindow) {
454 $bearsamppWinbinder->messageBoxError(
455 sprintf($bearsamppLang->getValue(Lang::BEARSAMPP_CONF_NOT_FOUND_ERROR), $this->getName() . ' ' . $version),
456 $boxTitle
457 );
458 }
459 return false;
460 }
461
462 $bearsamppConfRaw = parse_ini_file($bearsamppConf);
463 if ($bearsamppConfRaw === false || !isset($bearsamppConfRaw[self::ROOT_CFG_VERSION]) || $bearsamppConfRaw[self::ROOT_CFG_VERSION] != $version) {
464 Util::logError('bearsampp config file malformed for ' . $this->getName() . ' ' . $version);
465 if ($showWindow) {
466 $bearsamppWinbinder->messageBoxError(
467 sprintf($bearsamppLang->getValue(Lang::BEARSAMPP_CONF_MALFORMED_ERROR), $this->getName() . ' ' . $version),
468 $boxTitle
469 );
470 }
471 return false;
472 }
473
474 // bearsampp.conf
475 $this->setVersion($version);
476
477 // conf
478 Util::replaceInFile($this->getConf(), array(
479 '/^port(.*?)=(.*?)(\d+)/' => 'port = ' . $this->port
480 ));
481
482 // phpmyadmin
483 $bearsamppApps->getPhpmyadmin()->update($sub + 1);
484
485 // adminer
486 $bearsamppApps->getAdminer()->update($sub + 1);
487
488 return true;
489 }
setVersion($version)
const BEARSAMPP_CONF_NOT_FOUND_ERROR
const SWITCH_VERSION_TITLE
const BEARSAMPP_CONF_MALFORMED_ERROR
static replaceInFile($path, $replaceList)

References Module\$bearsamppConf, Module\$bearsamppConfRaw, $bearsamppLang, $conf, Module\$version, Lang\BEARSAMPP_CONF_MALFORMED_ERROR, Lang\BEARSAMPP_CONF_NOT_FOUND_ERROR, getConf(), Module\getName(), Module\getVersion(), Util\logDebug(), Util\logError(), Util\replaceInFile(), setVersion(), and Lang\SWITCH_VERSION_TITLE.

Referenced by switchVersion().

+ Here is the caller graph for this function:

Field Documentation

◆ $admin

BinMariadb::$admin
private

Definition at line 44 of file class.bin.mariadb.php.

Referenced by getAdmin().

◆ $cliExe

BinMariadb::$cliExe
private

Definition at line 43 of file class.bin.mariadb.php.

Referenced by getCliExe().

◆ $conf

BinMariadb::$conf
private

Definition at line 39 of file class.bin.mariadb.php.

Referenced by getConf(), and updateConfig().

◆ $errorLog

BinMariadb::$errorLog
private

Definition at line 36 of file class.bin.mariadb.php.

Referenced by getErrorLog().

◆ $exe

BinMariadb::$exe
private

Definition at line 38 of file class.bin.mariadb.php.

Referenced by getExe().

◆ $port

BinMariadb::$port
private

Definition at line 40 of file class.bin.mariadb.php.

Referenced by changePort(), checkPort(), getPort(), and setPort().

◆ $rootPwd

BinMariadb::$rootPwd
private

Definition at line 42 of file class.bin.mariadb.php.

Referenced by getRootPwd(), and setRootPwd().

◆ $rootUser

BinMariadb::$rootUser
private

Definition at line 41 of file class.bin.mariadb.php.

Referenced by getRootUser(), and setRootUser().

◆ $service

BinMariadb::$service
private

Definition at line 35 of file class.bin.mariadb.php.

Referenced by getService().

◆ CMD_SYNTAX_CHECK

const BinMariadb::CMD_SYNTAX_CHECK = '--help --verbose 1>NUL'

◆ CMD_VARIABLES

const BinMariadb::CMD_VARIABLES = 'variables'

◆ CMD_VERSION

const BinMariadb::CMD_VERSION = '--version'

◆ LOCAL_CFG_ADMIN

const BinMariadb::LOCAL_CFG_ADMIN = 'mariadbAdmin'

Definition at line 25 of file class.bin.mariadb.php.

Referenced by reload().

◆ LOCAL_CFG_CLI_EXE

const BinMariadb::LOCAL_CFG_CLI_EXE = 'mariadbCliExe'

Definition at line 24 of file class.bin.mariadb.php.

Referenced by reload().

◆ LOCAL_CFG_CONF

const BinMariadb::LOCAL_CFG_CONF = 'mariadbConf'

Definition at line 26 of file class.bin.mariadb.php.

Referenced by reload().

◆ LOCAL_CFG_EXE

const BinMariadb::LOCAL_CFG_EXE = 'mariadbExe'

Definition at line 23 of file class.bin.mariadb.php.

Referenced by reload().

◆ LOCAL_CFG_PORT

const BinMariadb::LOCAL_CFG_PORT = 'mariadbPort'

Definition at line 27 of file class.bin.mariadb.php.

Referenced by reload(), and replaceAll().

◆ LOCAL_CFG_ROOT_PWD

const BinMariadb::LOCAL_CFG_ROOT_PWD = 'mariadbRootPwd'

Definition at line 29 of file class.bin.mariadb.php.

Referenced by reload(), and replaceAll().

◆ LOCAL_CFG_ROOT_USER

const BinMariadb::LOCAL_CFG_ROOT_USER = 'mariadbRootUser'

Definition at line 28 of file class.bin.mariadb.php.

Referenced by reload(), and replaceAll().

◆ ROOT_CFG_ENABLE

const BinMariadb::ROOT_CFG_ENABLE = 'mariadbEnable'

Definition at line 20 of file class.bin.mariadb.php.

◆ ROOT_CFG_VERSION

const BinMariadb::ROOT_CFG_VERSION = 'mariadbVersion'

Definition at line 21 of file class.bin.mariadb.php.

◆ SERVICE_NAME


The documentation for this class was generated from the following file: