Bearsampp 2026.3.26
API documentation
Loading...
Searching...
No Matches
class.bin.mysql.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: Bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
16class BinMysql extends Module
17{
18 const SERVICE_NAME = 'bearsamppmysql';
19
20 const ROOT_CFG_ENABLE = 'mysqlEnable';
21 const ROOT_CFG_VERSION = 'mysqlVersion';
22
23 const LOCAL_CFG_EXE = 'mysqlExe';
24 const LOCAL_CFG_CLI_EXE = 'mysqlCliExe';
25 const LOCAL_CFG_ADMIN = 'mysqlAdmin';
26 const LOCAL_CFG_CONF = 'mysqlConf';
27 const LOCAL_CFG_PORT = 'mysqlPort';
28 const LOCAL_CFG_ROOT_USER = 'mysqlRootUser';
29 const LOCAL_CFG_ROOT_PWD = 'mysqlRootPwd';
30
31 const CMD_VERSION = '--version';
32 const CMD_VARIABLES = 'variables';
33 const CMD_SYNTAX_CHECK = '--help --verbose 1>NUL';
34
35 private $service;
36 private $errorLog;
37
38 private $exe;
39 private $conf;
40 private $port;
41 private $rootUser;
42 private $rootPwd;
43 private $cliExe;
44 private $admin;
45 private $dataDir;
46
53 public function __construct($id, $type)
54 {
55 Util::logInitClass($this);
56 $this->reload($id, $type);
57 }
58
65 public function reload($id = null, $type = null)
66 {
69
70 $this->name = $bearsamppLang->getValue(Lang::MYSQL);
71 $this->version = $bearsamppConfig->getRaw(self::ROOT_CFG_VERSION);
72 parent::reload($id, $type);
73
74 $this->enable = $this->enable && $bearsamppConfig->getRaw(self::ROOT_CFG_ENABLE);
75 $this->service = new Win32Service(self::SERVICE_NAME);
76 $this->errorLog = $bearsamppRoot->getLogsPath() . '/mysql.log';
77
78 if ($this->bearsamppConfRaw !== false) {
79 $this->exe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_EXE];
80 $this->conf = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CONF];
81 $this->port = $this->bearsamppConfRaw[self::LOCAL_CFG_PORT];
82 $this->rootUser = isset($this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_USER]) ? $this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_USER] : 'root';
83 $this->rootPwd = isset($this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_PWD]) ? $this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_PWD] : '';
84 $this->cliExe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CLI_EXE];
85 $this->admin = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_ADMIN];
86 $this->dataDir = $this->symlinkPath . '/data';
87 }
88
89 if (!$this->enable) {
90 Util::logInfo($this->name . ' is not enabled!');
91
92 return;
93 }
94 if (!is_dir($this->currentPath)) {
95 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->currentPath));
96
97 return;
98 }
99 if (!is_dir($this->symlinkPath)) {
100 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->symlinkPath));
101
102 return;
103 }
104 if (!is_file($this->bearsamppConf)) {
105 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->bearsamppConf));
106
107 return;
108 }
109 if (!is_file($this->exe)) {
110 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->exe));
111
112 return;
113 }
114 if (!is_file($this->conf)) {
115 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->conf));
116
117 return;
118 }
119 if (!is_numeric($this->port) || $this->port <= 0) {
120 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_INVALID_PARAMETER), self::LOCAL_CFG_PORT, $this->port));
121
122 return;
123 }
124 if (empty($this->rootUser)) {
125 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_INVALID_PARAMETER), self::LOCAL_CFG_ROOT_USER, $this->rootUser));
126
127 return;
128 }
129 if (!is_file($this->cliExe)) {
130 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->cliExe));
131
132 return;
133 }
134 if (!is_file($this->admin)) {
135 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->admin));
136
137 return;
138 }
139
140 $this->service->setDisplayName(APP_TITLE . ' ' . $this->getName());
141 $this->service->setBinPath($this->exe);
142 $this->service->setParams(self::SERVICE_NAME);
143 $this->service->setStartType(Win32Service::SERVICE_DEMAND_START);
144 $this->service->setErrorControl(Win32Service::SERVER_ERROR_NORMAL);
145 }
146
152 protected function replaceAll($params)
153 {
154 $content = file_get_contents($this->bearsamppConf);
155
156 foreach ($params as $key => $value) {
157 $content = preg_replace('|' . $key . ' = .*|', $key . ' = ' . '"' . $value . '"', $content);
158 $this->bearsamppConfRaw[$key] = $value;
159 switch ($key) {
160 case self::LOCAL_CFG_PORT:
161 $this->port = $value;
162 break;
163 case self::LOCAL_CFG_ROOT_USER:
164 $this->rootUser = $value;
165 break;
166 case self::LOCAL_CFG_ROOT_PWD:
167 $this->rootPwd = $value;
168 break;
169 }
170 }
171
172 file_put_contents($this->bearsamppConf, $content);
173 }
174
184 public function changePort($port, $checkUsed = false, $wbProgressBar = null)
185 {
186 global $bearsamppWinbinder;
187
188 if (!Util::isValidPort($port)) {
189 Util::logError($this->getName() . ' port not valid: ' . $port);
190
191 return false;
192 }
193
194 $port = intval($port);
195 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
196
197 $isPortInUse = Util::isPortInUse($port);
198 if (!$checkUsed || $isPortInUse === false) {
199 // bearsampp.conf
200 $this->setPort($port);
201 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
202
203 // conf
204 $this->update();
205 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
206
207 return true;
208 }
209
210 Util::logDebug($this->getName() . ' port in used: ' . $port . ' - ' . $isPortInUse);
211
212 return $isPortInUse;
213 }
214
223 public function checkPort($port, $showWindow = false)
224 {
225 global $bearsamppLang, $bearsamppWinbinder;
226 $boxTitle = sprintf($bearsamppLang->getValue(Lang::CHECK_PORT_TITLE), $this->getName(), $port);
227 $startTime = microtime(true);
228
229 if (!Util::isValidPort($port)) {
230 Util::logError($this->getName() . ' port not valid: ' . $port);
231 return false;
232 }
233
234 // Quick socket check first - much faster than PDO connection
235 $timeout = 1; // Reduced timeout for better performance
236 $fp = @fsockopen('127.0.0.1', $port, $errno, $errstr, $timeout);
237 if (!$fp) {
238 Util::logDebug($this->getName() . ' port ' . $port . ' is not used');
239 if ($showWindow) {
240 $bearsamppWinbinder->messageBoxError(
241 sprintf($bearsamppLang->getValue(Lang::PORT_NOT_USED), $port),
242 $boxTitle
243 );
244 }
245 return false;
246 }
247 fclose($fp);
248
249 // Use cached connection if available for better performance
250 static $cachedConnection = null;
251 static $lastPort = null;
252
253 if ($cachedConnection === null || $lastPort !== $port) {
254 try {
255 // Use new constant name for PHP 8.5+ while maintaining backward compatibility
256 // Check PHP version to avoid deprecation warnings
257 if (PHP_VERSION_ID >= 80500) {
258 $initCommandAttr = \Pdo\Mysql::ATTR_INIT_COMMAND;
259 } else {
260 $initCommandAttr = \PDO::MYSQL_ATTR_INIT_COMMAND;
261 }
262
263 $options = [
264 \PDO::ATTR_TIMEOUT => $timeout,
265 \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
266 $initCommandAttr => "SET SESSION sql_mode=''"
267 ];
268
269 $dsn = 'mysql:host=127.0.0.1;port=' . $port;
270 $cachedConnection = new \PDO($dsn, $this->rootUser, $this->rootPwd, $options);
271 $lastPort = $port;
272 } catch (\PDOException $e) {
273 Util::logDebug($this->getName() . ' port ' . $port . ' connection failed: ' . $e->getMessage());
274 if ($showWindow) {
275 $bearsamppWinbinder->messageBoxWarning(
276 sprintf($bearsamppLang->getValue(Lang::PORT_NOT_USED_BY), $port),
277 $boxTitle
278 );
279 }
280 return false;
281 }
282 }
283
284 try {
285 // Single optimized query to get both version and type
286 $stmt = $cachedConnection->query("SELECT @@version, @@version_comment");
287 $row = $stmt->fetch(\PDO::FETCH_NUM);
288
289 if (!$row) {
290 return false;
291 }
292
293 $version = explode('-', $row[0]);
294 $version = count($version) > 1 ? $version[0] : $row[0];
295 $isMysql = Util::startWith(strtolower($row[1]), 'mysql');
296
297 if (!$isMysql) {
298 Util::logDebug($this->getName() . ' port used by another DBMS: ' . $port);
299 if ($showWindow) {
300 $bearsamppWinbinder->messageBoxWarning(
302 $boxTitle
303 );
304 }
305 return false;
306 }
307
308 Util::logDebug($this->getName() . ' port ' . $port . ' is used by: ' . $this->getName() . ' ' . $version);
309 if ($showWindow) {
310 $bearsamppWinbinder->messageBoxInfo(
311 sprintf($bearsamppLang->getValue(Lang::PORT_USED_BY), $port, $this->getName() . ' ' . $version),
312 $boxTitle
313 );
314 }
315
316 $totalTime = round(microtime(true) - $startTime, 2);
317 Util::logTrace("MySQL port check completed in {$totalTime}s");
318 return true;
319
320 } catch (\PDOException $e) {
321 Util::logDebug($this->getName() . ' port ' . $port . ' validation error: ' . $e->getMessage());
322 if ($showWindow) {
323 $bearsamppWinbinder->messageBoxWarning(
324 sprintf($bearsamppLang->getValue(Lang::PORT_NOT_USED_BY), $port),
325 $boxTitle
326 );
327 }
328 return false;
329 }
330 }
331
341 public function changeRootPassword($currentPwd, $newPwd, $wbProgressBar = null)
342 {
343 global $bearsamppWinbinder;
344 $startTime = microtime(true);
345 $error = null;
346 $timeout = 5; // 5 seconds timeout
347
348 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
349
350 try {
351 // Connect using PDO
352 $options = [
353 \PDO::ATTR_TIMEOUT => $timeout,
354 \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION
355 ];
356
357 $dsn = 'mysql:host=127.0.0.1;port=' . $this->port;
358 $dbLink = new \PDO($dsn, $this->rootUser, $currentPwd, $options);
359
360 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
361
362 // Determine MySQL version to use appropriate password update syntax
363 $stmt = $dbLink->query('SELECT VERSION()');
364 $version = $stmt->fetchColumn();
365
366 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
367
368 // Use appropriate SQL syntax based on MySQL version
369 if (version_compare($version, '5.7.6', '>=')) {
370 // MySQL 5.7.6 and newer uses ALTER USER
371 $sql = "ALTER USER '{$this->rootUser}'@'localhost' IDENTIFIED BY :password";
372 $stmt = $dbLink->prepare($sql);
373 $stmt->bindParam(':password', $newPwd);
374 } else {
375 // Older versions use SET PASSWORD
376 $sql = "SET PASSWORD FOR '{$this->rootUser}'@'localhost' = PASSWORD(:password)";
377 $stmt = $dbLink->prepare($sql);
378 $stmt->bindParam(':password', $newPwd);
379 }
380
381 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
382 $stmt->execute();
383
384 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
385 $dbLink->query('FLUSH PRIVILEGES');
386
387 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
388 $dbLink = null; // Close connection properly
389
390 } catch (\PDOException $e) {
391 $error = $e->getMessage();
392 }
393
394 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
395
396 if (!empty($error)) {
397 $totalTime = round(microtime(true) - $startTime, 2);
398 Util::logTrace("MySQL password change failed in {$totalTime}s: " . $error);
399
400 return $error;
401 }
402
403 // bearsampp.conf
404 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
405 $this->setRootPwd($newPwd);
406
407 // conf
408 $this->update();
409 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
410
411 $totalTime = round(microtime(true) - $startTime, 2);
412 Util::logTrace("MySQL password change completed in {$totalTime}s");
413
414 return true;
415 }
416
425 public function checkRootPassword($currentPwd = null, $wbProgressBar = null)
426 {
427 global $bearsamppWinbinder;
428 $startTime = microtime(true);
429 $currentPwd = $currentPwd == null ? $this->rootPwd : $currentPwd;
430 $error = null;
431 $timeout = 2; // Reduced timeout for faster validation
432
433 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
434
435 // Use cached connection for password validation if available
436 static $passwordCache = [];
437 $cacheKey = md5($this->rootUser . ':' . $currentPwd . ':' . $this->port);
438
439 if (isset($passwordCache[$cacheKey]) && (time() - $passwordCache[$cacheKey]['time']) < 30) {
440 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
441 $totalTime = round(microtime(true) - $startTime, 2);
442 Util::logTrace("MySQL password check completed from cache in {$totalTime}s");
443 return $passwordCache[$cacheKey]['result'];
444 }
445
446 try {
447 // Use new constant name for PHP 8.5+ while maintaining backward compatibility
448 // Check PHP version to avoid deprecation warnings
449 if (PHP_VERSION_ID >= 80500) {
450 $initCommandAttr = \Pdo\Mysql::ATTR_INIT_COMMAND;
451 } else {
452 $initCommandAttr = \PDO::MYSQL_ATTR_INIT_COMMAND;
453 }
454
455 $options = [
456 \PDO::ATTR_TIMEOUT => $timeout,
457 \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
458 $initCommandAttr => "SET SESSION sql_mode=''"
459 ];
460
461 $dsn = 'mysql:host=127.0.0.1;port=' . $this->port;
462 $dbLink = new \PDO($dsn, $this->rootUser, $currentPwd, $options);
463
464 // Quick validation query
465 $dbLink->query('SELECT 1');
466 $dbLink = null; // Close connection properly
467
468 // Cache successful result
469 $passwordCache[$cacheKey] = [
470 'result' => true,
471 'time' => time()
472 ];
473
474 } catch (\PDOException $e) {
475 $error = $e->getMessage();
476
477 // Cache failed result for shorter time
478 $passwordCache[$cacheKey] = [
479 'result' => $error,
480 'time' => time() - 25 // Cache for only 5 seconds
481 ];
482 }
483
484 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
485
486 if (!empty($error)) {
487 $totalTime = round(microtime(true) - $startTime, 2);
488 Util::logTrace("MySQL password check failed in {$totalTime}s: " . $error);
489 return $error;
490 }
491
492 $totalTime = round(microtime(true) - $startTime, 2);
493 Util::logTrace("MySQL password check completed in {$totalTime}s");
494 return true;
495 }
496
505 public function switchVersion($version, $showWindow = false)
506 {
507 Util::logDebug('Switch ' . $this->name . ' version to ' . $version);
508
509 return $this->updateConfig($version, 0, $showWindow);
510 }
511
521 protected function updateConfig($version = null, $sub = 0, $showWindow = false)
522 {
523 global $bearsamppLang, $bearsamppBins, $bearsamppApps, $bearsamppWinbinder;
524
525 if (!$this->enable) {
526 return true;
527 }
528
529 $version = $version == null ? $this->version : $version;
530 Util::logDebug(($sub > 0 ? str_repeat(' ', 2 * $sub) : '') . 'Update ' . $this->name . ' ' . $version . ' config');
531
532 $boxTitle = sprintf($bearsamppLang->getValue(Lang::SWITCH_VERSION_TITLE), $this->getName(), $version);
533
534 $currentPath = str_replace('mysql' . $this->getVersion(), 'mysql' . $version, $this->getCurrentPath());
535 $conf = str_replace('mysql' . $this->getVersion(), 'mysql' . $version, $this->getConf());
536 $bearsamppConf = str_replace('mysql' . $this->getVersion(), 'mysql' . $version, $this->bearsamppConf);
537
538 if ($this->version != $version) {
540 }
541
542 if (!file_exists($conf) || !file_exists($bearsamppConf)) {
543 Util::logError('bearsampp config files not found for ' . $this->getName() . ' ' . $version);
544 if ($showWindow) {
545 $bearsamppWinbinder->messageBoxError(
546 sprintf($bearsamppLang->getValue(Lang::BEARSAMPP_CONF_NOT_FOUND_ERROR), $this->getName() . ' ' . $version),
547 $boxTitle
548 );
549 }
550
551 return false;
552 }
553
554 $bearsamppConfRaw = parse_ini_file($bearsamppConf);
555 if ($bearsamppConfRaw === false || !isset($bearsamppConfRaw[self::ROOT_CFG_VERSION]) || $bearsamppConfRaw[self::ROOT_CFG_VERSION] != $version) {
556 Util::logError('bearsampp config file malformed for ' . $this->getName() . ' ' . $version);
557 if ($showWindow) {
558 $bearsamppWinbinder->messageBoxError(
559 sprintf($bearsamppLang->getValue(Lang::BEARSAMPP_CONF_MALFORMED_ERROR), $this->getName() . ' ' . $version),
560 $boxTitle
561 );
562 }
563
564 return false;
565 }
566
567 // bearsampp.conf
568 $this->setVersion($version);
569
570 // conf
571 Util::replaceInFile($this->getConf(), array(
572 '/^port(.*?)=(.*?)(\d+)/' => 'port = ' . $this->port
573 ));
574
575 // phpmyadmin
576 $bearsamppApps->getPhpmyadmin()->update($sub + 1);
577
578 // php
579 $bearsamppBins->getPhp()->update($sub + 1);
580
581 return true;
582 }
583
593 public function initData($path = null, $version = null)
594 {
595 Util::logTrace('Starting MySQL data initialization');
596 $startTime = microtime(true);
597
598 $path = $path != null ? $path : $this->getCurrentPath();
599 $version = $version != null ? $version : $this->getVersion();
600 $dataDir = $path . '/data';
601 $perfSchemaDir = $dataDir . '/performance_schema';
602
603 if (version_compare($version, '5.7.0', '<')) {
604 Util::logTrace('MySQL version below 5.7.0, skipping initialization');
605
606 return true;
607 }
608
609 $needsInit = false;
610
611 if (!is_dir($dataDir)) {
612 Util::logTrace('MySQL data directory does not exist; initialization required');
613 $needsInit = true;
614 } else {
615 if (!is_dir($perfSchemaDir)) {
616 Util::logTrace('performance_schema directory missing; reinitialization required');
617 $needsInit = true;
618 }
619 }
620
621 if (!$needsInit) {
622 Util::logTrace('MySQL data directory already initialized');
623
624 return true;
625 }
626
627 // Prepare a clean data directory (mysqld --initialize-insecure requires an empty/nonexistent directory)
628 if (is_dir($dataDir)) {
629 $backupDir = $dataDir . '_bak_' . date('Ymd_His');
630 if (@rename($dataDir, $backupDir)) {
631 Util::logTrace('Backed up existing data directory to: ' . $backupDir);
632 } else {
633 Util::logTrace('Failed to backup existing data directory; attempting to clear it');
634 try {
635 $it = new \RecursiveDirectoryIterator($dataDir, \FilesystemIterator::SKIP_DOTS);
636 $files = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST);
637 foreach ($files as $file) {
638 if ($file->isDir()) {
639 @rmdir($file->getPathname());
640 } else {
641 @unlink($file->getPathname());
642 }
643 }
644 @rmdir($dataDir);
645 } catch (\Throwable $t) {
646 Util::logTrace('Error clearing data directory: ' . $t->getMessage());
647 }
648 }
649 }
650
651 if (!is_dir($dataDir)) {
652 @mkdir($dataDir, 0777, true);
653 Util::logTrace('Created clean MySQL data directory');
654 }
655
656 // Use Bearsampp built-in initialization (init.bat via Batch)
657 try {
659 } catch (\Throwable $e) {
660 Util::logTrace('Error during MySQL initialization via Batch: ' . $e->getMessage());
661
662 return false;
663 }
664
665 // Verify initialization by checking performance_schema existence
666 if (!is_dir($perfSchemaDir)) {
667 Util::logTrace('MySQL initialization appears to have failed: performance_schema still missing');
668
669 return false;
670 }
671
672 $totalTime = round(microtime(true) - $startTime, 2);
673 Util::logTrace("MySQL initialization completed in {$totalTime}s");
674
675 return true;
676 }
677
685 public function getCmdLineOutput($cmd)
686 {
687 $result = array(
688 'syntaxOk' => false,
689 'content' => null,
690 );
691
692 $bin = $this->getExe();
693 $removeLines = 0;
694 $outputFrom = '';
695 if ($cmd == self::CMD_SYNTAX_CHECK) {
696 $outputFrom = '2';
697 } elseif ($cmd == self::CMD_VARIABLES) {
698 $bin = $this->getAdmin();
699 $cmd .= ' --user=' . $this->getRootUser();
700 if ($this->getRootPwd()) {
701 $cmd .= ' --password=' . $this->getRootPwd();
702 }
703 $removeLines = 2;
704 }
705
706 if (file_exists($bin)) {
707 $tmpResult = Batch::exec('mysqlGetCmdLineOutput', '"' . $bin . '" ' . $cmd . ' ' . $outputFrom, 5);
708 if ($tmpResult !== false && is_array($tmpResult)) {
709 $result['syntaxOk'] = empty($tmpResult) || !Util::contains(trim($tmpResult[count($tmpResult) - 1]), '[ERROR]');
710 for ($i = 0; $i < $removeLines; $i++) {
711 unset($tmpResult[$i]);
712 }
713 $result['content'] = trim(str_replace($bin, '', implode(PHP_EOL, $tmpResult)));
714 }
715 }
716
717 return $result;
718 }
719
725 public function setVersion($version)
726 {
727 global $bearsamppConfig;
728 $this->version = $version;
729 $bearsamppConfig->replace(self::ROOT_CFG_VERSION, $version);
730 $this->reload();
731 }
732
738 public function getService()
739 {
740 return $this->service;
741 }
742
749 public function setEnable($enabled, $showWindow = false)
750 {
751 global $bearsamppConfig, $bearsamppLang, $bearsamppWinbinder;
752
753 if ($enabled == Config::ENABLED && !is_dir($this->currentPath)) {
754 Util::logDebug($this->getName() . ' cannot be enabled because bundle ' . $this->getVersion() . ' does not exist in ' . $this->currentPath);
755 if ($showWindow) {
756 $bearsamppWinbinder->messageBoxError(
757 sprintf($bearsamppLang->getValue(Lang::ENABLE_BUNDLE_NOT_EXIST), $this->getName(), $this->getVersion(), $this->currentPath),
758 sprintf($bearsamppLang->getValue(Lang::ENABLE_TITLE), $this->getName())
759 );
760 }
761 $enabled = Config::DISABLED;
762 }
763
764 Util::logInfo($this->getName() . ' switched to ' . ($enabled == Config::ENABLED ? 'enabled' : 'disabled'));
765 $this->enable = $enabled == Config::ENABLED;
766 $bearsamppConfig->replace(self::ROOT_CFG_ENABLE, $enabled);
767
768 $this->reload();
769 if ($this->enable) {
770 Util::installService($this, $this->port, self::CMD_SYNTAX_CHECK, $showWindow);
771 } else {
772 Util::removeService($this->service, $this->name);
773 }
774 }
775
781 public function getErrorLog()
782 {
783 return $this->errorLog;
784 }
785
791 public function getExe()
792 {
793 return $this->exe;
794 }
795
801 public function getConf()
802 {
803 return $this->conf;
804 }
805
811 public function getPort()
812 {
813 return $this->port;
814 }
815
821 public function setPort($port)
822 {
823 $this->replace(self::LOCAL_CFG_PORT, $port);
824 }
825
831 public function getRootUser()
832 {
833 return $this->rootUser;
834 }
835
841 public function setRootUser($rootUser)
842 {
843 $this->replace(self::LOCAL_CFG_ROOT_USER, $rootUser);
844 }
845
851 public function getRootPwd()
852 {
853 return $this->rootPwd;
854 }
855
861 public function setRootPwd($rootPwd)
862 {
863 $this->replace(self::LOCAL_CFG_ROOT_PWD, $rootPwd);
864 }
865
871 public function getCliExe()
872 {
873 return $this->cliExe;
874 }
875
881 public function getAdmin()
882 {
883 return $this->admin;
884 }
885
891 public function getDataDir()
892 {
893 return $this->dataDir;
894 }
895}
$result
global $bearsamppBins
global $bearsamppLang
global $bearsamppRoot
static initializeMysql($path)
static exec($basename, $content, $timeout=true, $catchOutput=true, $standalone=false, $silent=true, $rebuild=true)
const LOCAL_CFG_EXE
const SERVICE_NAME
const CMD_SYNTAX_CHECK
const CMD_VERSION
replaceAll($params)
updateConfig($version=null, $sub=0, $showWindow=false)
const LOCAL_CFG_ROOT_PWD
const CMD_VARIABLES
getCmdLineOutput($cmd)
const LOCAL_CFG_ROOT_USER
setRootUser($rootUser)
changeRootPassword($currentPwd, $newPwd, $wbProgressBar=null)
switchVersion($version, $showWindow=false)
const LOCAL_CFG_PORT
const ROOT_CFG_ENABLE
setVersion($version)
checkPort($port, $showWindow=false)
changePort($port, $checkUsed=false, $wbProgressBar=null)
setEnable($enabled, $showWindow=false)
const LOCAL_CFG_CONF
const LOCAL_CFG_CLI_EXE
initData($path=null, $version=null)
const LOCAL_CFG_ADMIN
reload($id=null, $type=null)
const ROOT_CFG_VERSION
__construct($id, $type)
checkRootPassword($currentPwd=null, $wbProgressBar=null)
setRootPwd($rootPwd)
const DISABLED
const ENABLED
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 PORT_NOT_USED
const ERROR_INVALID_PARAMETER
const ENABLE_TITLE
const MYSQL
const PORT_NOT_USED_BY
const SWITCH_VERSION_TITLE
const CHECK_PORT_TITLE
const PORT_USED_BY
const PORT_USED_BY_ANOTHER_DBMS
const ERROR_FILE_NOT_FOUND
update($sub=0, $showWindow=false)
replace($key, $value)
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 isPortInUse($port)
static replaceInFile($path, $replaceList)
global $bearsamppConfig
Definition homepage.php:41
const APP_TITLE
Definition root.php:13