Bearsampp 2026.9.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 ()
 getDataDir ()
 getErrorLog ()
 getExe ()
 getPort ()
 getRootPwd ()
 getRootUser ()
 getService ()
 initData ($path=null, $version=null)
 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 ()
 getId ()
 getName ()
 getRelease ()
 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
 $currentPath
 $rootPath
 $symlinkPath

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

Static Public Member Functions inherited from Module
static clearMemoryCache ()
static invalidateConfigCacheForPath ($sourcePath)
Protected Attributes inherited from Module
 $bearsamppConf
 $bearsamppConfRaw
 $enable
 $name
 $release = 'N/A'
 $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 118 of file class.bin.mariadb.php.

119 {
120 Log::initClass($this);
121 $this->reload($id, $type);
122 }
reload($id=null, $type=null)
static initClass($classInstance)

References Module\$id, Module\$type, Log\initClass(), and reload().

Here is the call graph for this function:

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

251 {
252 global $bearsamppWinbinder;
253
254 if (!Util::isValidPort($port)) {
255 Log::error($this->getName() . ' port not valid: ' . $port);
256
257 return false;
258 }
259
260 $port = intval($port);
261 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
262
263 $isPortInUse = ServiceHelper::isPortInUse($port);
264 if (!$checkUsed || $isPortInUse === false) {
265 // bearsampp.conf
266 $this->setPort($port);
267 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
268
269 // conf
270 $this->update();
271 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
272
273 return true;
274 }
275
276 Log::debug($this->getName() . ' port in used: ' . $port . ' - ' . $isPortInUse);
277
278 return $isPortInUse;
279 }
static debug($data, $file=null)
static error($data, $file=null)
update($sub=0, $showWindow=false)
static isPortInUse($port)
static isValidPort($port)

References $port, Log\debug(), Log\error(), Module\getName(), ServiceHelper\isPortInUse(), Util\isValidPort(), setPort(), and Module\update().

Here is the call graph for this function:

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

379 {
380 global $bearsamppWinbinder;
381
382 $error = null;
383 $dbLink = false;
384
385 try {
386 // Connect
387 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
388
389 // Since PHP 8.1 mysqli defaults to exception mode (MYSQLI_REPORT_STRICT),
390 // so a failed auth throws mysqli_sql_exception instead of returning false.
391 // Reset to OFF so calls return false and mysqli_connect_error() is set,
392 // keeping the documented bool|string contract and avoiding an uncaught
393 // exception that would freeze the WinBinder GUI thread.
394 mysqli_report(MYSQLI_REPORT_OFF);
395
396 $dbLink = mysqli_init();
397 mysqli_options($dbLink, MYSQLI_OPT_CONNECT_TIMEOUT, 5);
398 if (!mysqli_real_connect($dbLink, APP_LOCALHOST, $this->rootUser, $currentPwd, null, $this->port)) {
399 throw new \RuntimeException(mysqli_connect_error());
400 }
401
402 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
403
404 // Bound metadata-lock/table-lock waits so a password change can
405 // never freeze the UI: any lock contention times out in seconds
406 // instead of waiting for the server's default (often very large)
407 // lock_wait_timeout.
408 mysqli_query($dbLink, 'SET SESSION lock_wait_timeout = 5');
409 mysqli_query($dbLink, 'SET SESSION innodb_lock_wait_timeout = 5');
410
411 // ALTER USER works reliably across MariaDB 10.3+ and avoids
412 // known SET PASSWORD bugs (MDEV-16774, MDEV-17136) and
413 // metadata lock contention on the mysql.user table in 10.3.
414 // The user and host are given explicitly (not CURRENT_USER()).
415 // The password is escaped so an empty (blank) password is
416 // allowed: IDENTIFIED BY '' sets a blank password.
417 $escapedUser = mysqli_real_escape_string($dbLink, $this->rootUser);
418 $escapedPwd = mysqli_real_escape_string($dbLink, $newPwd);
419 $sql = "ALTER USER '" . $escapedUser . "'@'localhost' IDENTIFIED BY '" . $escapedPwd . "'";
420
421 if (mysqli_query($dbLink, $sql) === false) {
422 throw new \RuntimeException(mysqli_error($dbLink));
423 }
424
425 // Preserve the existing progress-step count.
426 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
427 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
428
429 mysqli_close($dbLink);
430 $dbLink = false;
431
432 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
433 } catch (\Throwable $e) {
434 $error = $e->getMessage();
435
436 if ($dbLink) {
437 @mysqli_close($dbLink);
438 }
439 }
440
441 if (!empty($error)) {
442 return $error;
443 }
444
445 // bearsampp.conf
446 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
447 $this->setRootPwd($newPwd);
448
449 // conf
450 $this->update();
451 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
452
453 return true;
454 }
setRootPwd($rootPwd)
const APP_LOCALHOST
Definition root.php:21

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

Here is the call graph for this function:

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

290 {
291 global $bearsamppLang, $bearsamppWinbinder;
292 $boxTitle = sprintf($bearsamppLang->getValue(Lang::CHECK_PORT_TITLE), $this->getName(), $port);
293
294 if (!Util::isValidPort($port)) {
295 Log::error($this->getName() . ' port not valid: ' . $port);
296
297 return false;
298 }
299
300 $fp = @fsockopen(APP_LOCALHOST, $port, $errno, $errstr, 5);
301 if ($fp) {
302 // Reset mysqli to non-exception mode so connect/query failures
303 // return false instead of throwing an uncaught mysqli_sql_exception
304 // that would freeze the WinBinder GUI thread.
305 mysqli_report(MYSQLI_REPORT_OFF);
306
307 $dbLink = mysqli_connect(APP_LOCALHOST . ':' . $port, $this->rootUser, $this->rootPwd);
308 $isMariadb = false;
309 $version = false;
310
311 if ($dbLink) {
312 $result = mysqli_query($dbLink, 'SHOW VARIABLES');
313 if ($result) {
314 while (false !== ($row = mysqli_fetch_array($result, MYSQLI_NUM))) {
315 if ($row[0] == 'version') {
316 $version = explode('-', $row[1]);
317 $version = count($version) > 1 ? $version[0] : $row[1];
318 }
319 if ($row[0] == 'version_comment' && UtilString::startWith(strtolower($row[1]), 'mariadb')) {
320 $isMariadb = true;
321 }
322 if ($isMariadb && $version !== false) {
323 break;
324 }
325 }
326 if (!$isMariadb) {
327 Log::debug($this->getName() . ' port used by another DBMS: ' . $port);
328 if ($showWindow) {
329 $bearsamppWinbinder->messageBoxWarning(
331 $boxTitle
332 );
333 }
334 } else {
335 Log::debug($this->getName() . ' port ' . $port . ' is used by: ' . $this->getName() . ' ' . $version);
336 if ($showWindow) {
337 $bearsamppWinbinder->messageBoxInfo(
338 sprintf($bearsamppLang->getValue(Lang::PORT_USED_BY), $port, $this->getName() . ' ' . $version),
339 $boxTitle
340 );
341 }
342
343 return true;
344 }
345 }
346 mysqli_close($dbLink);
347 } else {
348 Log::debug($this->getName() . ' port ' . $port . ' is used by another application');
349 if ($showWindow) {
350 $bearsamppWinbinder->messageBoxWarning(
351 sprintf($bearsamppLang->getValue(Lang::PORT_NOT_USED_BY), $port),
352 $boxTitle
353 );
354 }
355 }
356 } else {
357 Log::debug($this->getName() . ' port ' . $port . ' is not used');
358 if ($showWindow) {
359 $bearsamppWinbinder->messageBoxError(
360 sprintf($bearsamppLang->getValue(Lang::PORT_NOT_USED), $port),
361 $boxTitle
362 );
363 }
364 }
365
366 return false;
367 }
$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, APP_LOCALHOST, Lang\CHECK_PORT_TITLE, Log\debug(), Log\error(), Module\getName(), Util\isValidPort(), Lang\PORT_NOT_USED, Lang\PORT_NOT_USED_BY, Lang\PORT_USED_BY, Lang\PORT_USED_BY_ANOTHER_DBMS, and UtilString\startWith().

Here is the call graph for this function:

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

465 {
466 global $bearsamppWinbinder;
467 $currentPwd = $currentPwd == null ? $this->rootPwd : $currentPwd;
468 $error = null;
469
470 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
471
472 // Reset mysqli to non-exception mode so a bad password returns false
473 // (with mysqli_connect_error() set) instead of throwing an uncaught
474 // mysqli_sql_exception that would freeze the WinBinder GUI thread.
475 mysqli_report(MYSQLI_REPORT_OFF);
476
477 $dbLink = mysqli_init();
478 mysqli_options($dbLink, MYSQLI_OPT_CONNECT_TIMEOUT, 5);
479 if (!mysqli_real_connect($dbLink, APP_LOCALHOST, $this->rootUser, $currentPwd, null, $this->port)) {
480 $error = mysqli_connect_error();
481 }
482
483 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
484 if ($dbLink) {
485 mysqli_close($dbLink);
486 }
487
488 if (!empty($error)) {
489 return $error;
490 }
491
492 return true;
493 }

References APP_LOCALHOST.

◆ getAdmin()

getAdmin ( )

Retrieves the admin executable path for the module.

Returns
string The admin executable path.

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

780 {
781 return $this->admin;
782 }

References $admin.

Referenced by getCmdLineOutput().

Here is the caller graph for this function:

◆ getCliExe()

getCliExe ( )

Retrieves the CLI executable path for the module.

Returns
string The CLI executable path.

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

770 {
771 return $this->cliExe;
772 }

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

584 {
585 $result = array(
586 'syntaxOk' => false,
587 'content' => null,
588 );
589
590 $bin = $this->getExe();
591 $removeLines = 0;
592 $outputFrom = '';
593 if ($cmd == self::CMD_SYNTAX_CHECK) {
594 $outputFrom = '2';
595 } elseif ($cmd == self::CMD_VARIABLES) {
596 $bin = $this->getAdmin();
597 $cmd .= ' --user=' . $this->getRootUser();
598 if ($this->getRootPwd()) {
599 $cmd .= ' --password=' . $this->getRootPwd();
600 }
601 $removeLines = 2;
602 }
603
604 if (file_exists($bin)) {
605 $tmpResult = Batch::exec('mariadbGetCmdLineOutput', '"' . $bin . '" ' . $cmd . ' ' . $outputFrom, 5);
606 if ($tmpResult !== false && is_array($tmpResult)) {
607 $result['syntaxOk'] = empty($tmpResult) || !UtilString::contains(trim($tmpResult[count($tmpResult) - 1]), '[ERROR]');
608 for ($i = 0; $i < $removeLines; $i++) {
609 unset($tmpResult[$i]);
610 }
611 $result['content'] = trim(str_replace($bin, '', implode(PHP_EOL, $tmpResult)));
612 }
613 }
614
615 return $result;
616 }
static exec($basename, $content, $timeout=true, $catchOutput=true, $standalone=false, $silent=true, $rebuild=true)
static contains($string, $search)

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

Here is the call graph for this function:

◆ getConf()

getConf ( )

Retrieves the configuration file path for the module.

Returns
string The configuration file path.

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

700 {
701 return $this->conf;
702 }

References $conf.

Referenced by updateConfig().

Here is the caller graph for this function:

◆ getDataDir()

getDataDir ( )

Retrieves the data directory path for MariaDB.

Returns
string The data directory path.

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

790 {
791 return $this->currentPath . '/data';
792 }

◆ getErrorLog()

getErrorLog ( )

Retrieves the error log path for the module.

Returns
string The error log path.

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

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

References $errorLog.

◆ getExe()

getExe ( )

Retrieves the executable path for the module.

Returns
string The executable path.

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

690 {
691 return $this->exe;
692 }

References $exe.

Referenced by getCmdLineOutput().

Here is the caller graph for this function:

◆ getPort()

getPort ( )

Retrieves the port number for the module.

Returns
int The port number.

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

710 {
711 return $this->port;
712 }

References $port.

◆ getRootPwd()

getRootPwd ( )

Retrieves the root password for the module.

Returns
string The root password.

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

750 {
751 return $this->rootPwd;
752 }

References $rootPwd.

Referenced by getCmdLineOutput().

Here is the caller graph for this function:

◆ getRootUser()

getRootUser ( )

Retrieves the root user for the module.

Returns
string The root user.

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

730 {
731 return $this->rootUser;
732 }

References $rootUser.

Referenced by getCmdLineOutput().

Here is the caller graph for this function:

◆ getService()

getService ( )

Retrieves the service associated with the module.

Returns
Win32Service The service object.

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

637 {
638 return $this->service;
639 }

References $service.

◆ initData()

initData ( $path = null,
$version = null )

Initializes the MariaDB data directory if needed.

Parameters
string | null$pathThe path to the MariaDB installation. If null, the current path is used.
string | null$versionThe version of MariaDB. If null, the current version is used.
Returns
bool True if initialization was successful or not needed

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

803 {
804 Log::trace('Starting MariaDB data initialization');
805 $startTime = microtime(true);
806
807 $path = $path != null ? $path : Path::getModuleCurrentPath($this);
808 $version = $version != null ? $version : $this->getVersion();
809 $dataDir = $path . '/data';
810
811 if (is_dir($dataDir . '/mysql')) {
812 Log::trace('MariaDB data directory already initialized');
813
814 return true;
815 }
816
817 if (!is_dir($dataDir)) {
818 @mkdir($dataDir, 0777, true);
819 Log::trace('Created MariaDB data directory');
820 }
821
822 // Check for init.bat first
823 if (file_exists($path . '/init.bat')) {
824 Log::trace('Initializing MariaDB via init.bat');
825 try {
827 } catch (\Throwable $e) {
828 Log::trace('Error during MariaDB initialization via Batch: ' . $e->getMessage());
829
830 return false;
831 }
832 } else {
833 // Use mariadb-install-db.exe
834 Log::trace('Initializing MariaDB via mariadb-install-db.exe');
835 $installDbExe = $path . '/bin/mariadb-install-db.exe';
836 if (!file_exists($installDbExe)) {
837 $installDbExe = $path . '/bin/mysql_install_db.exe';
838 }
839
840 if (file_exists($installDbExe)) {
841 $cmd = '"' . Path::formatWindowsPath($installDbExe) . '"';
842 $cmd .= ' --datadir="' . Path::formatWindowsPath($dataDir) . '"';
843
844 try {
845 Batch::exec('initializeMariadb', $cmd, 60);
846 } catch (\Throwable $e) {
847 Log::trace('Error during MariaDB initialization via mariadb-install-db: ' . $e->getMessage());
848
849 return false;
850 }
851 } else {
852 Log::error('MariaDB initialization failed: No init.bat or mariadb-install-db.exe found');
853
854 return false;
855 }
856 }
857
858 // Verify initialization
859 if (!is_dir($dataDir . '/mysql')) {
860 Log::trace('MariaDB initialization appears to have failed: mysql directory still missing');
861
862 return false;
863 }
864
865 $totalTime = round(microtime(true) - $startTime, 2);
866 Log::trace("MariaDB initialization completed in {$totalTime}s");
867
868 return true;
869 }
static initializeMariadb($path)
static trace($data, $file=null)
static formatWindowsPath($path)
static getModuleCurrentPath($module)

References Module\$version, Log\error(), Batch\exec(), Path\formatWindowsPath(), Path\getModuleCurrentPath(), Module\getVersion(), Batch\initializeMariadb(), and Log\trace().

Here is the call graph for this function:

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

131 {
133 Log::reloadClass($this);
134
135 $this->name = $bearsamppLang->getValue(Lang::MARIADB);
136 $this->version = $bearsamppConfig->getRaw(self::ROOT_CFG_VERSION);
137 parent::reload($id, $type);
138
139 $this->enable = $this->enable && $bearsamppConfig->getRaw(self::ROOT_CFG_ENABLE);
140 $this->service = new Win32Service(self::SERVICE_NAME);
141 $this->errorLog = Path::getLogsPath() . '/mariadb.log';
142
143 if ($this->bearsamppConfRaw !== false) {
144 $this->exe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_EXE];
145 $this->conf = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CONF];
146 $this->port = $this->bearsamppConfRaw[self::LOCAL_CFG_PORT];
147 $this->rootUser = isset($this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_USER]) ? $this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_USER] : 'root';
148 $this->rootPwd = isset($this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_PWD]) ? $this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_PWD] : '';
149 $this->cliExe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CLI_EXE];
150 $this->admin = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_ADMIN];
151 }
152
153 if (!$this->enable) {
154 Log::info($this->name . ' is not enabled!');
155
156 return;
157 }
158 if (!is_dir($this->currentPath)) {
159 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->currentPath));
160
161 return;
162 }
163 if (!is_dir($this->symlinkPath)) {
164 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->symlinkPath));
165
166 return;
167 }
168 if (!is_file($this->bearsamppConf)) {
169 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->bearsamppConf));
170
171 return;
172 }
173 if (!is_file($this->exe)) {
174 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->exe));
175
176 return;
177 }
178 if (!is_file($this->conf)) {
179 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->conf));
180
181 return;
182 }
183 if (!is_numeric($this->port) || $this->port <= 0) {
184 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_INVALID_PARAMETER), self::LOCAL_CFG_PORT, $this->port));
185
186 return;
187 }
188 if (empty($this->rootUser)) {
189 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_INVALID_PARAMETER), self::LOCAL_CFG_ROOT_USER, $this->rootUser));
190
191 return;
192 }
193 if (!is_file($this->cliExe)) {
194 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->cliExe));
195
196 return;
197 }
198 if (!is_file($this->admin)) {
199 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->admin));
200
201 return;
202 }
203
204 $this->service->setDisplayName(APP_TITLE . ' ' . $this->getName());
205 $this->service->setBinPath($this->exe);
206 $this->service->setParams('--defaults-file="' . Path::formatWindowsPath($this->conf) . '" ' . self::SERVICE_NAME);
207 $this->service->setStartType(Win32Service::SERVICE_DEMAND_START);
208 $this->service->setErrorControl(Win32Service::SERVER_ERROR_NORMAL);
209 }
global $bearsamppRoot
const MARIADB
const ERROR_EXE_NOT_FOUND
const ERROR_CONF_NOT_FOUND
const ERROR_INVALID_PARAMETER
const ERROR_FILE_NOT_FOUND
static info($data, $file=null)
static reloadClass($classInstance)
static getLogsPath($aetrayPath=false)
global $bearsamppConfig
Definition homepage.php:46
const APP_TITLE
Definition root.php:19

References $bearsamppConfig, $bearsamppLang, $bearsamppRoot, Module\$id, Module\$type, APP_TITLE, Log\error(), Lang\ERROR_CONF_NOT_FOUND, Lang\ERROR_EXE_NOT_FOUND, Lang\ERROR_FILE_NOT_FOUND, Lang\ERROR_INVALID_PARAMETER, Path\formatWindowsPath(), Path\getLogsPath(), Module\getName(), Log\info(), Lang\MARIADB, Log\reloadClass(), Win32Service\SERVER_ERROR_NORMAL, and Win32Service\SERVICE_DEMAND_START.

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

Here is the call graph for this function:
Here is the caller graph for this function:

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

217 {
218 $content = file_get_contents($this->bearsamppConf);
219
220 foreach ($params as $key => $value) {
221 $content = preg_replace('|' . $key . ' = .*|', $key . ' = ' . '"' . $value . '"', $content);
222 $this->bearsamppConfRaw[$key] = $value;
223 switch ($key) {
224 case self::LOCAL_CFG_PORT:
225 $this->port = $value;
226 break;
227 case self::LOCAL_CFG_ROOT_USER:
228 $this->rootUser = $value;
229 break;
230 case self::LOCAL_CFG_ROOT_PWD:
231 $this->rootPwd = $value;
232 break;
233 }
234 }
235
236 file_put_contents($this->bearsamppConf, $content);
237
238 self::invalidateConfigCacheForPath($this->bearsamppConf);
239 }
static invalidateConfigCacheForPath($sourcePath)

References Module\invalidateConfigCacheForPath().

Here is the call graph for this function:

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

648 {
649 global $bearsamppConfig, $bearsamppLang, $bearsamppWinbinder;
650
651 if ($enabled == Config::ENABLED && !is_dir($this->currentPath)) {
652 Log::debug($this->getName() . ' cannot be enabled because bundle ' . $this->getVersion() . ' does not exist in ' . $this->currentPath);
653 if ($showWindow) {
654 $bearsamppWinbinder->messageBoxError(
655 sprintf($bearsamppLang->getValue(Lang::ENABLE_BUNDLE_NOT_EXIST), $this->getName(), $this->getVersion(), $this->currentPath),
656 sprintf($bearsamppLang->getValue(Lang::ENABLE_TITLE), $this->getName())
657 );
658 }
659 $enabled = Config::DISABLED;
660 }
661
662 Log::info($this->getName() . ' switched to ' . ($enabled == Config::ENABLED ? 'enabled' : 'disabled'));
663 $this->enable = $enabled == Config::ENABLED;
664 $bearsamppConfig->replace(self::ROOT_CFG_ENABLE, $enabled);
665
666 $this->reload();
667 if ($this->enable) {
668 ServiceHelper::installService($this, $this->port, self::CMD_SYNTAX_CHECK, $showWindow);
669 } else {
670 ServiceHelper::removeService($this->service, $this->name);
671 }
672 }
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, Log\debug(), Config\DISABLED, Lang\ENABLE_BUNDLE_NOT_EXIST, Lang\ENABLE_TITLE, Config\ENABLED, Module\getName(), Module\getVersion(), Log\info(), ServiceHelper\installService(), reload(), and ServiceHelper\removeService().

Here is the call graph for this function:

◆ setPort()

setPort ( $port)

Sets the port number for the module.

Parameters
int$portThe port number to set.

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

720 {
721 $this->replace(self::LOCAL_CFG_PORT, $port);
722 }
replace($key, $value)

References $port, and Module\replace().

Referenced by changePort().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setRootPwd()

setRootPwd ( $rootPwd)

Sets the root password for the module.

Parameters
string$rootPwdThe root password to set.

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

760 {
761 $this->replace(self::LOCAL_CFG_ROOT_PWD, $rootPwd);
762 }

References $rootPwd, and Module\replace().

Referenced by changeRootPassword().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setRootUser()

setRootUser ( $rootUser)

Sets the root user for the module.

Parameters
string$rootUserThe root user to set.

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

740 {
741 $this->replace(self::LOCAL_CFG_ROOT_USER, $rootUser);
742 }

References $rootUser, and Module\replace().

Here is the call graph for this function:

◆ setVersion()

setVersion ( $version)

Sets the version of the module.

Parameters
string$versionThe version to set.

Reimplemented from Module.

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

624 {
625 global $bearsamppConfig;
626 $this->version = $version;
627 $bearsamppConfig->replace(self::ROOT_CFG_VERSION, $version);
628 $this->reload();
629 }

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

Referenced by updateConfig().

Here is the call graph for this function:
Here is the caller graph for this function:

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

504 {
505 Log::debug('Switch ' . $this->name . ' version to ' . $version);
506
507 return $this->updateConfig($version, 0, $showWindow);
508 }
updateConfig($version=null, $sub=0, $showWindow=false)

References Module\$version, Log\debug(), and updateConfig().

Here is the call graph for this function:

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

520 {
521 global $bearsamppLang, $bearsamppApps, $bearsamppWinbinder;
522
523 if (!$this->enable) {
524 return true;
525 }
526
527 $version = $version == null ? $this->version : $version;
528 Log::debug(($sub > 0 ? str_repeat(' ', 2 * $sub) : '') . 'Update ' . $this->name . ' ' . $version . ' config');
529
530 $boxTitle = sprintf($bearsamppLang->getValue(Lang::SWITCH_VERSION_TITLE), $this->getName(), $version);
531
532 $conf = str_replace('mariadb' . $this->getVersion(), 'mariadb' . $version, $this->getConf());
533 $bearsamppConf = str_replace('mariadb' . $this->getVersion(), 'mariadb' . $version, $this->bearsamppConf);
534
535 if (!file_exists($conf) || !file_exists($bearsamppConf)) {
536 Log::error('bearsampp config files not found for ' . $this->getName() . ' ' . $version);
537 if ($showWindow) {
538 $bearsamppWinbinder->messageBoxError(
539 sprintf($bearsamppLang->getValue(Lang::BEARSAMPP_CONF_NOT_FOUND_ERROR), $this->getName() . ' ' . $version),
540 $boxTitle
541 );
542 }
543
544 return false;
545 }
546
547 $bearsamppConfRaw = parse_ini_file($bearsamppConf);
548 if ($bearsamppConfRaw === false || !isset($bearsamppConfRaw[self::ROOT_CFG_VERSION]) || $bearsamppConfRaw[self::ROOT_CFG_VERSION] != $version) {
549 Log::error('bearsampp config file malformed for ' . $this->getName() . ' ' . $version);
550 if ($showWindow) {
551 $bearsamppWinbinder->messageBoxError(
552 sprintf($bearsamppLang->getValue(Lang::BEARSAMPP_CONF_MALFORMED_ERROR), $this->getName() . ' ' . $version),
553 $boxTitle
554 );
555 }
556
557 return false;
558 }
559
560 // bearsampp.conf
561 $this->setVersion($version);
562
563 // conf
564 Util::replaceInFile($this->getConf(), array(
565 '/^port(.*?)=(.*?)(\d+)/' => 'port = ' . $this->port
566 ));
567
568 // phpmyadmin
569 $bearsamppApps->getPhpmyadmin()->update($sub + 1);
570
571 return true;
572 }
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, Log\debug(), Log\error(), getConf(), Module\getName(), Module\getVersion(), Util\replaceInFile(), setVersion(), and Lang\SWITCH_VERSION_TITLE.

Referenced by switchVersion().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ $admin

$admin
private

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

Referenced by getAdmin().

◆ $cliExe

$cliExe
private

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

Referenced by getCliExe().

◆ $conf

$conf
private

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

Referenced by getConf(), and updateConfig().

◆ $errorLog

$errorLog
private

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

Referenced by getErrorLog().

◆ $exe

$exe
private

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

Referenced by getExe().

◆ $port

$port
private

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

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

◆ $rootPwd

$rootPwd
private

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

Referenced by getRootPwd(), and setRootPwd().

◆ $rootUser

$rootUser
private

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

Referenced by getRootUser(), and setRootUser().

◆ $service

$service
private

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

Referenced by getService().

◆ CMD_SYNTAX_CHECK

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

◆ CMD_VARIABLES

const CMD_VARIABLES = 'variables'

Command line option to display MariaDB server variables.

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

Referenced by ActionDebugMariadb\getCommandMapping(), and TplAppMariadb\getMenuMariadbDebug().

◆ CMD_VERSION

const CMD_VERSION = '--version'

Command line option to display the MariaDB version.

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

Referenced by ActionDebugMariadb\getCommandMapping(), and TplAppMariadb\getMenuMariadbDebug().

◆ LOCAL_CFG_ADMIN

const LOCAL_CFG_ADMIN = 'mariadbAdmin'

Configuration key for the MariaDB admin executable in the local configuration.

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

◆ LOCAL_CFG_CLI_EXE

const LOCAL_CFG_CLI_EXE = 'mariadbCliExe'

Configuration key for the MariaDB CLI executable in the local configuration.

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

◆ LOCAL_CFG_CONF

const LOCAL_CFG_CONF = 'mariadbConf'

Configuration key for the MariaDB configuration file in the local configuration.

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

◆ LOCAL_CFG_EXE

const LOCAL_CFG_EXE = 'mariadbExe'

Configuration key for the MariaDB executable in the local configuration.

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

◆ LOCAL_CFG_PORT

const LOCAL_CFG_PORT = 'mariadbPort'

Configuration key for the MariaDB port in the local configuration.

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

◆ LOCAL_CFG_ROOT_PWD

const LOCAL_CFG_ROOT_PWD = 'mariadbRootPwd'

Configuration key for the MariaDB root password in the local configuration.

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

◆ LOCAL_CFG_ROOT_USER

const LOCAL_CFG_ROOT_USER = 'mariadbRootUser'

Configuration key for the MariaDB root user in the local configuration.

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

◆ ROOT_CFG_ENABLE

const ROOT_CFG_ENABLE = 'mariadbEnable'

Configuration key for the MariaDB enable flag in the root configuration.

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

◆ ROOT_CFG_VERSION

const ROOT_CFG_VERSION = 'mariadbVersion'

Configuration key for the MariaDB version in the root configuration.

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

◆ SERVICE_NAME


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