73 $this->enable = $this->enable &&
$bearsamppConfig->getRaw( self::ROOT_CFG_ENABLE );
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];
87 if ( !$this->enable ) {
92 if ( !is_dir( $this->currentPath ) ) {
97 if ( !is_dir( $this->symlinkPath ) ) {
102 if ( !is_file( $this->bearsamppConf ) ) {
107 if ( !is_file( $this->exe ) ) {
112 if ( !is_file( $this->conf ) ) {
117 if ( !is_numeric( $this->port ) || $this->port <= 0 ) {
122 if ( empty( $this->rootUser ) ) {
127 if ( !is_file( $this->cliExe ) ) {
132 if ( !is_file( $this->admin ) ) {
139 $this->service->setBinPath( $this->exe );
140 $this->service->setParams( self::SERVICE_NAME );
152 $content = file_get_contents( $this->bearsamppConf );
154 foreach ( $params as $key => $value ) {
155 $content = preg_replace(
'|' . $key .
' = .*|', $key .
' = ' .
'"' . $value .
'"', $content );
156 $this->bearsamppConfRaw[$key] = $value;
158 case self::LOCAL_CFG_PORT:
159 $this->port = $value;
161 case self::LOCAL_CFG_ROOT_USER:
162 $this->rootUser = $value;
164 case self::LOCAL_CFG_ROOT_PWD:
165 $this->rootPwd = $value;
170 file_put_contents( $this->bearsamppConf, $content );
184 global $bearsamppWinbinder;
193 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
196 if ( !$checkUsed || $isPortInUse ===
false ) {
199 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
203 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
232 $fp = @fsockopen(
'127.0.0.1',
$port, $errno, $errstr, 5 );
234 if ( version_compare( phpversion(),
'5.3' ) === -1 ) {
235 $dbLink = mysqli_connect(
'127.0.0.1', $this->rootUser, $this->rootPwd,
'',
$port );
238 $dbLink = mysqli_connect(
'127.0.0.1:' .
$port, $this->rootUser, $this->rootPwd );
244 $result = mysqli_query( $dbLink,
'SHOW VARIABLES' );
246 while (
false !== ($row = mysqli_fetch_array(
$result, MYSQLI_NUM )) ) {
247 if ( $row[0] ==
'version' ) {
251 if ( $row[0] ==
'version_comment' &&
Util::startWith( strtolower( $row[1] ),
'mariadb' ) ) {
254 if ( $isMariadb &&
$version !==
false ) {
261 $bearsamppWinbinder->messageBoxWarning(
270 $bearsamppWinbinder->messageBoxInfo(
279 mysqli_close( $dbLink );
284 $bearsamppWinbinder->messageBoxWarning(
294 $bearsamppWinbinder->messageBoxError(
315 global $bearsamppWinbinder;
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 );
323 $dbLink = @mysqli_connect(
'127.0.0.1:' . $this->port, $this->rootUser, $currentPwd );
326 $error = mysqli_connect_error();
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 );
335 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
336 if ( empty( $error ) && !@mysqli_stmt_bind_param( $stmt,
'ss', $newPwd, $this->rootUser ) ) {
337 $error = mysqli_stmt_error( $stmt );
340 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
341 if ( empty( $error ) && !@mysqli_stmt_execute( $stmt ) ) {
342 $error = mysqli_stmt_error( $stmt );
345 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
346 if ( $stmt !==
false ) {
347 mysqli_stmt_close( $stmt );
350 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
351 if ( empty( $error ) && @mysqli_query( $dbLink,
'FLUSH PRIVILEGES' ) ===
false ) {
352 $error = mysqli_error( $dbLink );
355 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
357 mysqli_close( $dbLink );
360 if ( !empty( $error ) ) {
365 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
370 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
385 global $bearsamppWinbinder;
386 $currentPwd = $currentPwd ==
null ? $this->rootPwd : $currentPwd;
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 );
394 $dbLink = @mysqli_connect(
'127.0.0.1:' . $this->port, $this->rootUser, $currentPwd );
397 $error = mysqli_connect_error();
400 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
402 mysqli_close( $dbLink );
405 if ( !empty( $error ) ) {
439 if (!$this->enable) {
444 Util::logDebug(($sub > 0 ? str_repeat(
' ', 2 * $sub) :
'') .
'Update ' . $this->name .
' ' .
$version .
' config');
454 $bearsamppWinbinder->messageBoxError(
466 $bearsamppWinbinder->messageBoxError(
479 '/^port(.*?)=(.*?)(\d+)/' =>
'port = ' . $this->port
483 $bearsamppApps->getPhpmyadmin()->update($sub + 1);
504 if ($cmd == self::CMD_SYNTAX_CHECK) {
506 } elseif ($cmd == self::CMD_VARIABLES) {
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]);
522 $result[
'content'] = trim(str_replace($bin,
'', implode(PHP_EOL, $tmpResult)));
556public function setEnable($enabled, $showWindow =
false) {
562 $bearsamppWinbinder->messageBoxError(
690 return $this->currentPath .
'/data';
704 $startTime = microtime(
true );
708 $dataDir = $path .
'/data';
710 if ( is_dir( $dataDir .
'/mysql' ) ) {
716 if ( !is_dir( $dataDir ) ) {
717 @mkdir( $dataDir, 0777,
true );
722 if ( file_exists( $path .
'/init.bat' ) ) {
726 }
catch ( \Throwable $e ) {
727 Util::logTrace(
'Error during MariaDB initialization via Batch: ' . $e->getMessage() );
733 Util::logTrace(
'Initializing MariaDB via mariadb-install-db.exe' );
734 $installDbExe = $path .
'/bin/mariadb-install-db.exe';
735 if ( !file_exists( $installDbExe ) ) {
736 $installDbExe = $path .
'/bin/mysql_install_db.exe';
739 if ( file_exists( $installDbExe ) ) {
745 }
catch ( \Throwable $e ) {
746 Util::logTrace(
'Error during MariaDB initialization via mariadb-install-db: ' . $e->getMessage() );
751 Util::logError(
'MariaDB initialization failed: No init.bat or mariadb-install-db.exe found' );
758 if ( !is_dir( $dataDir .
'/mysql' ) ) {
759 Util::logTrace(
'MariaDB initialization appears to have failed: mysql directory still missing' );
764 $totalTime = round( microtime(
true ) - $startTime, 2 );
765 Util::logTrace(
"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
update($sub=0, $showWindow=false)
static logError($data, $file=null)
static installService($bin, $port, $syntaxCheckCmd, $showWindow=false)
static logInitClass($classInstance)
static removeService($service, $name)
static logTrace($data, $file=null)
static isValidPort($port)
static logInfo($data, $file=null)
static contains($string, $search)
static logDebug($data, $file=null)
static logReloadClass($classInstance)
static startWith($string, $search)
static formatWindowsPath($path)
static isPortInUse($port)
static replaceInFile($path, $replaceList)
const SERVER_ERROR_NORMAL
const SERVICE_DEMAND_START