Bearsampp 2025.8.29
Loading...
Searching...
No Matches
BinMariadb Class Reference
Inheritance 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()

__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()

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()

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()

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
const PORT_NOT_USED_BY
const CHECK_PORT_TITLE
const PORT_USED_BY
const PORT_USED_BY_ANOTHER_DBMS
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()

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()

getAdmin ( )

Retrieves the admin executable path for the module.

Returns
string The admin executable path.

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

677 {
678 return $this->admin;
679}}

References $admin.

Referenced by getCmdLineOutput().

◆ getCliExe()

getCliExe ( )

Retrieves the CLI executable path for the module.

Returns
string The CLI executable path.

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

668 {
669 return $this->cliExe;
670}

References $cliExe.

◆ getCmdLineOutput()

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 495 of file class.bin.mariadb.php.

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

getConf ( )

Retrieves the configuration file path for the module.

Returns
string The configuration file path.

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

605 {
606 return $this->conf;
607}

References $conf.

Referenced by updateConfig().

◆ getErrorLog()

getErrorLog ( )

Retrieves the error log path for the module.

Returns
string The error log path.

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

587 {
588 return $this->errorLog;
589}

References $errorLog.

◆ getExe()

getExe ( )

Retrieves the executable path for the module.

Returns
string The executable path.

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

596 {
597 return $this->exe;
598}

References $exe.

Referenced by getCmdLineOutput().

◆ getPort()

getPort ( )

Retrieves the port number for the module.

Returns
int The port number.

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

614 {
615 return $this->port;
616}

References $port.

◆ getRootPwd()

getRootPwd ( )

Retrieves the root password for the module.

Returns
string The root password.

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

650 {
651 return $this->rootPwd;
652}

References $rootPwd.

Referenced by getCmdLineOutput().

◆ getRootUser()

getRootUser ( )

Retrieves the root user for the module.

Returns
string The root user.

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

632 {
633 return $this->rootUser;
634}

References $rootUser.

Referenced by getCmdLineOutput().

◆ getService()

getService ( )

Retrieves the service associated with the module.

Returns
Win32Service The service object.

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

546 {
547 return $this->service;
548}

References $service.

◆ reload()

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 MARIADB
const ERROR_EXE_NOT_FOUND
const ERROR_CONF_NOT_FOUND
const ERROR_INVALID_PARAMETER
const ERROR_FILE_NOT_FOUND
static logInfo($data, $file=null)
static logReloadClass($classInstance)
global $bearsamppConfig
Definition homepage.php:27
const APP_TITLE
Definition root.php:13

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(), Util\logError(), Util\logInfo(), Util\logReloadClass(), Lang\MARIADB, Win32Service\SERVER_ERROR_NORMAL, and Win32Service\SERVICE_DEMAND_START.

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

◆ replaceAll()

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 ) {
158 case self::LOCAL_CFG_PORT:
159 $this->port = $value;
160 break;
161 case self::LOCAL_CFG_ROOT_USER:
162 $this->rootUser = $value;
163 break;
164 case self::LOCAL_CFG_ROOT_PWD:
165 $this->rootPwd = $value;
166 break;
167 }
168 }
169
170 file_put_contents( $this->bearsamppConf, $content );
171 }

◆ setEnable()

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 556 of file class.bin.mariadb.php.

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

setPort ( $port)

Sets the port number for the module.

Parameters
int$portThe port number to set.

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

623 {
624 $this->replace(self::LOCAL_CFG_PORT, $port);
625}
replace($key, $value)

References $port, and Module\replace().

Referenced by changePort().

◆ setRootPwd()

setRootPwd ( $rootPwd)

Sets the root password for the module.

Parameters
string$rootPwdThe root password to set.

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

659 {
660 $this->replace(self::LOCAL_CFG_ROOT_PWD, $rootPwd);
661}

References $rootPwd, and Module\replace().

Referenced by changeRootPassword().

◆ setRootUser()

setRootUser ( $rootUser)

Sets the root user for the module.

Parameters
string$rootUserThe root user to set.

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

641 {
642 $this->replace(self::LOCAL_CFG_ROOT_USER, $rootUser);
643}

References $rootUser, and Module\replace().

◆ setVersion()

setVersion ( $version)

Sets the version of the module.

Parameters
string$versionThe version to set.

Reimplemented from Module.

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

534 {
535 global $bearsamppConfig;
536 $this->version = $version;
537 $bearsamppConfig->replace(self::ROOT_CFG_VERSION, $version);
538 $this->reload();
539}

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

Referenced by updateConfig().

◆ switchVersion()

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()

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 return true;
486 }
setVersion($version)
const BEARSAMPP_CONF_MALFORMED_ERROR
const BEARSAMPP_CONF_NOT_FOUND_ERROR
const SWITCH_VERSION_TITLE
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().

Field Documentation

◆ $admin

$admin
private

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

Referenced by getAdmin().

◆ $cliExe

$cliExe
private

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

Referenced by getCliExe().

◆ $conf

$conf
private

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

Referenced by getConf(), and updateConfig().

◆ $errorLog

$errorLog
private

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

Referenced by getErrorLog().

◆ $exe

$exe
private

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

Referenced by getExe().

◆ $port

$port
private

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

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

◆ $rootPwd

$rootPwd
private

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

Referenced by getRootPwd(), and setRootPwd().

◆ $rootUser

$rootUser
private

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

Referenced by getRootUser(), and setRootUser().

◆ $service

$service
private

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

Referenced by getService().

◆ CMD_SYNTAX_CHECK

◆ CMD_VARIABLES

const CMD_VARIABLES = 'variables'

◆ CMD_VERSION

const CMD_VERSION = '--version'

◆ LOCAL_CFG_ADMIN

const LOCAL_CFG_ADMIN = 'mariadbAdmin'

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

◆ LOCAL_CFG_CLI_EXE

const LOCAL_CFG_CLI_EXE = 'mariadbCliExe'

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

◆ LOCAL_CFG_CONF

const LOCAL_CFG_CONF = 'mariadbConf'

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

◆ LOCAL_CFG_EXE

const LOCAL_CFG_EXE = 'mariadbExe'

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

◆ LOCAL_CFG_PORT

const LOCAL_CFG_PORT = 'mariadbPort'

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

◆ LOCAL_CFG_ROOT_PWD

const LOCAL_CFG_ROOT_PWD = 'mariadbRootPwd'

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

◆ LOCAL_CFG_ROOT_USER

const LOCAL_CFG_ROOT_USER = 'mariadbRootUser'

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

◆ ROOT_CFG_ENABLE

const ROOT_CFG_ENABLE = 'mariadbEnable'

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

◆ ROOT_CFG_VERSION

const 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: