139 $this->enable = $this->enable &&
$bearsamppConfig->getRaw(self::ROOT_CFG_ENABLE);
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];
153 if (!$this->enable) {
154 Log::info($this->name .
' is not enabled!');
158 if (!is_dir($this->currentPath)) {
163 if (!is_dir($this->symlinkPath)) {
168 if (!is_file($this->bearsamppConf)) {
173 if (!is_file($this->exe)) {
178 if (!is_file($this->conf)) {
183 if (!is_numeric($this->port) || $this->port <= 0) {
188 if (empty($this->rootUser)) {
193 if (!is_file($this->cliExe)) {
198 if (!is_file($this->admin)) {
205 $this->service->setBinPath($this->exe);
206 $this->service->setParams(
'--defaults-file="' .
Path::formatWindowsPath($this->conf) .
'" ' . self::SERVICE_NAME);
218 $content = file_get_contents($this->bearsamppConf);
220 foreach ($params as $key => $value) {
221 $content = preg_replace(
'|' . $key .
' = .*|', $key .
' = ' .
'"' . $value .
'"', $content);
222 $this->bearsamppConfRaw[$key] = $value;
224 case self::LOCAL_CFG_PORT:
225 $this->port = $value;
227 case self::LOCAL_CFG_ROOT_USER:
228 $this->rootUser = $value;
230 case self::LOCAL_CFG_ROOT_PWD:
231 $this->rootPwd = $value;
236 file_put_contents($this->bearsamppConf, $content);
252 global $bearsamppWinbinder;
261 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
264 if (!$checkUsed || $isPortInUse ===
false) {
267 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
271 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
305 mysqli_report(MYSQLI_REPORT_OFF);
307 $dbLink = mysqli_connect(
APP_LOCALHOST .
':' .
$port, $this->rootUser, $this->rootPwd);
312 $result = mysqli_query($dbLink,
'SHOW VARIABLES');
314 while (
false !== ($row = mysqli_fetch_array(
$result, MYSQLI_NUM))) {
315 if ($row[0] ==
'version') {
322 if ($isMariadb &&
$version !==
false) {
329 $bearsamppWinbinder->messageBoxWarning(
337 $bearsamppWinbinder->messageBoxInfo(
346 mysqli_close($dbLink);
348 Log::debug($this->
getName() .
' port ' . $port .
' is used by another application');
350 $bearsamppWinbinder->messageBoxWarning(
359 $bearsamppWinbinder->messageBoxError(
380 global $bearsamppWinbinder;
387 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
394 mysqli_report(MYSQLI_REPORT_OFF);
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());
402 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
408 mysqli_query($dbLink,
'SET SESSION lock_wait_timeout = 5');
409 mysqli_query($dbLink,
'SET SESSION innodb_lock_wait_timeout = 5');
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 .
"'";
421 if (mysqli_query($dbLink, $sql) ===
false) {
422 throw new \RuntimeException(mysqli_error($dbLink));
426 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
427 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
429 mysqli_close($dbLink);
432 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
433 }
catch (\Throwable $e) {
434 $error = $e->getMessage();
437 @mysqli_close($dbLink);
441 if (!empty($error)) {
446 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
451 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
466 global $bearsamppWinbinder;
467 $currentPwd = $currentPwd ==
null ? $this->rootPwd : $currentPwd;
470 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
475 mysqli_report(MYSQLI_REPORT_OFF);
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();
483 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
485 mysqli_close($dbLink);
488 if (!empty($error)) {
523 if (!$this->enable) {
528 Log::debug(($sub > 0 ? str_repeat(
' ', 2 * $sub) :
'') .
'Update ' . $this->name .
' ' .
$version .
' config');
536 Log::error(
'bearsampp config files not found for ' . $this->
getName() .
' ' . $version);
538 $bearsamppWinbinder->messageBoxError(
549 Log::error(
'bearsampp config file malformed for ' . $this->
getName() .
' ' . $version);
551 $bearsamppWinbinder->messageBoxError(
565 '/^port(.*?)=(.*?)(\d+)/' =>
'port = ' . $this->port
569 $bearsamppApps->getPhpmyadmin()->update($sub + 1);
593 if ($cmd == self::CMD_SYNTAX_CHECK) {
595 } elseif ($cmd == self::CMD_VARIABLES) {
604 if (file_exists($bin)) {
605 $tmpResult =
Batch::exec(
'mariadbGetCmdLineOutput',
'"' . $bin .
'" ' . $cmd .
' ' . $outputFrom, 5);
606 if ($tmpResult !==
false && is_array($tmpResult)) {
608 for ($i = 0; $i < $removeLines; $i++) {
609 unset($tmpResult[$i]);
611 $result[
'content'] = trim(str_replace($bin,
'', implode(PHP_EOL, $tmpResult)));
647 public function setEnable($enabled, $showWindow =
false)
652 Log::debug($this->
getName() .
' cannot be enabled because bundle ' . $this->
getVersion() .
' does not exist in ' . $this->currentPath);
654 $bearsamppWinbinder->messageBoxError(
791 return $this->currentPath .
'/data';
804 Log::trace(
'Starting MariaDB data initialization');
805 $startTime = microtime(
true);
809 $dataDir = $path .
'/data';
811 if (is_dir($dataDir .
'/mysql')) {
812 Log::trace(
'MariaDB data directory already initialized');
817 if (!is_dir($dataDir)) {
818 @mkdir($dataDir, 0777,
true);
823 if (file_exists($path .
'/init.bat')) {
824 Log::trace(
'Initializing MariaDB via init.bat');
827 }
catch (\Throwable $e) {
828 Log::trace(
'Error during MariaDB initialization via Batch: ' . $e->getMessage());
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';
840 if (file_exists($installDbExe)) {
846 }
catch (\Throwable $e) {
847 Log::trace(
'Error during MariaDB initialization via mariadb-install-db: ' . $e->getMessage());
852 Log::error(
'MariaDB initialization failed: No init.bat or mariadb-install-db.exe found');
859 if (!is_dir($dataDir .
'/mysql')) {
860 Log::trace(
'MariaDB initialization appears to have failed: mysql directory still missing');
865 $totalTime = round(microtime(
true) - $startTime, 2);
866 Log::trace(
"MariaDB initialization completed in {$totalTime}s");
static initializeMariadb($path)
static exec($basename, $content, $timeout=true, $catchOutput=true, $standalone=false, $silent=true, $rebuild=true)
updateConfig($version=null, $sub=0, $showWindow=false)
const LOCAL_CFG_ROOT_USER
changeRootPassword($currentPwd, $newPwd, $wbProgressBar=null)
switchVersion($version, $showWindow=false)
checkPort($port, $showWindow=false)
changePort($port, $checkUsed=false, $wbProgressBar=null)
setEnable($enabled, $showWindow=false)
initData($path=null, $version=null)
reload($id=null, $type=null)
checkRootPassword($currentPwd=null, $wbProgressBar=null)
const ENABLE_BUNDLE_NOT_EXIST
const BEARSAMPP_CONF_MALFORMED_ERROR
const ERROR_EXE_NOT_FOUND
const ERROR_CONF_NOT_FOUND
const BEARSAMPP_CONF_NOT_FOUND_ERROR
const ERROR_INVALID_PARAMETER
const SWITCH_VERSION_TITLE
const PORT_USED_BY_ANOTHER_DBMS
const ERROR_FILE_NOT_FOUND
static info($data, $file=null)
static debug($data, $file=null)
static reloadClass($classInstance)
static trace($data, $file=null)
static error($data, $file=null)
static initClass($classInstance)
update($sub=0, $showWindow=false)
static invalidateConfigCacheForPath($sourcePath)
static getLogsPath($aetrayPath=false)
static formatWindowsPath($path)
static getModuleCurrentPath($module)
static installService($bin, $port, $syntaxCheckCmd, $showWindow=false)
static removeService($service, $name)
static isPortInUse($port)
static isValidPort($port)
static replaceInFile($path, $replaceList)
static contains($string, $search)
static startWith($string, $search)
const SERVER_ERROR_NORMAL
const SERVICE_DEMAND_START