2024.8.23
Loading...
Searching...
No Matches
BinMysql Class Reference
+ Inheritance diagram for BinMysql:
+ Collaboration diagram for BinMysql:

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 ()
 
 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 ()
 
 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 = 'mysqlAdmin'
 
const LOCAL_CFG_CLI_EXE = 'mysqlCliExe'
 
const LOCAL_CFG_CONF = 'mysqlConf'
 
const LOCAL_CFG_EXE = 'mysqlExe'
 
const LOCAL_CFG_PORT = 'mysqlPort'
 
const LOCAL_CFG_ROOT_PWD = 'mysqlRootPwd'
 
const LOCAL_CFG_ROOT_USER = 'mysqlRootUser'
 
const ROOT_CFG_ENABLE = 'mysqlEnable'
 
const ROOT_CFG_VERSION = 'mysqlVersion'
 
const SERVICE_NAME = 'bearsamppmysql'
 
- 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 BinMysql

This class represents the MySQL binary module in the Bearsampp application. It handles the configuration, management, and operations related to MySQL.

Definition at line 16 of file class.bin.mysql.php.

Constructor & Destructor Documentation

◆ __construct()

BinMysql::__construct ( $id,
$type )

Constructs a BinMysql object and initializes the MySQL module.

Parameters
string$idThe ID of the module.
string$typeThe type of the module.

Definition at line 52 of file class.bin.mysql.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()

BinMysql::changePort ( $port,
$checkUsed = false,
$wbProgressBar = null )

Changes the MySQL port and updates the configuration.

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 an error message if the port is in use.

Definition at line 182 of file class.bin.mysql.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()

BinMysql::changeRootPassword ( $currentPwd,
$newPwd,
$wbProgressBar = null )

Changes the MySQL root password.

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 the operation failed.

Definition at line 313 of file class.bin.mysql.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()

BinMysql::checkPort ( $port,
$showWindow = false )

Checks if the specified port is in use by MySQL.

Parameters
int$portThe port number to check.
bool$showWindowWhether to show a message box with the result.
Returns
bool True if the port is in use by MySQL, false otherwise.

Definition at line 221 of file class.bin.mysql.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 $isMysql = 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] ), 'mysql' ) ) {
252 $isMysql = true;
253 }
254 if ( $isMysql && $version !== false ) {
255 break;
256 }
257 }
258 if ( !$isMysql ) {
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_BY
const PORT_USED_BY_ANOTHER_DBMS
const CHECK_PORT_TITLE
const PORT_USED_BY
const PORT_NOT_USED
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()

BinMysql::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 the operation failed.

Definition at line 383 of file class.bin.mysql.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()

BinMysql::getAdmin ( )

Retrieves the path to the MySQL admin executable.

Returns
string The path to the admin executable.

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

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

References $admin.

Referenced by getCmdLineOutput().

+ Here is the caller graph for this function:

◆ getCliExe()

BinMysql::getCliExe ( )

Retrieves the path to the MySQL CLI executable.

Returns
string The path to the CLI executable.

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

720 {
721 return $this->cliExe;
722 }

References $cliExe.

◆ getCmdLineOutput()

BinMysql::getCmdLineOutput ( $cmd)

Executes a MySQL command and retrieves the output.

Parameters
string$cmdThe command to execute.
Returns
array An associative array containing 'syntaxOk' (boolean) and 'content' (string|null).

Definition at line 531 of file class.bin.mysql.php.

532 {
533 $result = array(
534 'syntaxOk' => false,
535 'content' => null,
536 );
537
538 $bin = $this->getExe();
539 $removeLines = 0;
540 $outputFrom = '';
541 if ( $cmd == self::CMD_SYNTAX_CHECK ) {
542 $outputFrom = '2';
543 }
544 elseif ( $cmd == self::CMD_VARIABLES ) {
545 $bin = $this->getAdmin();
546 $cmd .= ' --user=' . $this->getRootUser();
547 if ( $this->getRootPwd() ) {
548 $cmd .= ' --password=' . $this->getRootPwd();
549 }
550 $removeLines = 2;
551 }
552
553 if ( file_exists( $bin ) ) {
554 $tmpResult = Batch::exec( 'mysqlGetCmdLineOutput', '"' . $bin . '" ' . $cmd . ' ' . $outputFrom, 5 );
555 if ( $tmpResult !== false && is_array( $tmpResult ) ) {
556 $result['syntaxOk'] = empty( $tmpResult ) || !Util::contains( trim( $tmpResult[count( $tmpResult ) - 1] ), '[ERROR]' );
557 for ( $i = 0; $i < $removeLines; $i++ ) {
558 unset( $tmpResult[$i] );
559 }
560 $result['content'] = trim( str_replace( $bin, '', implode( PHP_EOL, $tmpResult ) ) );
561 }
562 }
563
564 return $result;
565 }
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()

BinMysql::getConf ( )

Retrieves the path to the MySQL configuration file.

Returns
string The path to the configuration file.

Definition at line 649 of file class.bin.mysql.php.

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

References $conf.

Referenced by updateConfig().

+ Here is the caller graph for this function:

◆ getErrorLog()

BinMysql::getErrorLog ( )

Retrieves the path to the MySQL error log.

Returns
string The path to the error log.

Definition at line 629 of file class.bin.mysql.php.

630 {
631 return $this->errorLog;
632 }

References $errorLog.

◆ getExe()

BinMysql::getExe ( )

Retrieves the path to the MySQL executable.

Returns
string The path to the MySQL executable.

Definition at line 639 of file class.bin.mysql.php.

640 {
641 return $this->exe;
642 }

References $exe.

Referenced by getCmdLineOutput().

+ Here is the caller graph for this function:

◆ getPort()

BinMysql::getPort ( )

Retrieves the MySQL port number.

Returns
int The port number.

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

660 {
661 return $this->port;
662 }

References $port.

◆ getRootPwd()

BinMysql::getRootPwd ( )

Retrieves the MySQL root password.

Returns
string The root password.

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

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

References $rootPwd.

Referenced by getCmdLineOutput().

+ Here is the caller graph for this function:

◆ getRootUser()

BinMysql::getRootUser ( )

Retrieves the MySQL root username.

Returns
string The root username.

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

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

References $rootUser.

Referenced by getCmdLineOutput().

+ Here is the caller graph for this function:

◆ getService()

BinMysql::getService ( )

Retrieves the MySQL service object.

Returns
Win32Service The MySQL service object.

Definition at line 585 of file class.bin.mysql.php.

586 {
587 return $this->service;
588 }

References $service.

◆ initData()

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

Initializes the MySQL data directory if it does not exist.

Parameters
string | null$pathThe path to the MySQL installation. If null, the current path is used.
string | null$versionThe version of MySQL. If null, the current version is used.

Definition at line 508 of file class.bin.mysql.php.

509 {
510 $path = $path != null ? $path : $this->getCurrentPath();
511 $version = $version != null ? $version : $this->getVersion();
512
513 if ( version_compare( $version, '5.7.0', '<' ) ) {
514 return;
515 }
516
517 if ( file_exists( $path . '/data' ) ) {
518 return;
519 }
520
521 Batch::initializeMysql( $path );
522 }
static initializeMysql($path)

References Module\$version, Module\getCurrentPath(), Module\getVersion(), and Batch\initializeMysql().

Referenced by updateConfig().

+ Here is the caller graph for this function:

◆ reload()

BinMysql::reload ( $id = null,
$type = null )

Reloads the MySQL 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.mysql.php.

65 {
67 Util::logReloadClass( $this );
68
69 $this->name = $bearsamppLang->getValue( Lang::MYSQL );
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() . '/mysql.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 LOCAL_CFG_EXE
const LOCAL_CFG_CLI_EXE
const LOCAL_CFG_ROOT_PWD
const LOCAL_CFG_PORT
const LOCAL_CFG_ADMIN
const LOCAL_CFG_ROOT_USER
const LOCAL_CFG_CONF
const MYSQL
const ERROR_FILE_NOT_FOUND
const ERROR_INVALID_PARAMETER
const ERROR_CONF_NOT_FOUND
const ERROR_EXE_NOT_FOUND
static logReloadClass($classInstance)
static logInfo($data, $file=null)
global $bearsamppConfig
Definition homepage.php:26
const APP_TITLE
Definition root.php:12

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(), LOCAL_CFG_ADMIN, LOCAL_CFG_CLI_EXE, LOCAL_CFG_CONF, LOCAL_CFG_EXE, LOCAL_CFG_PORT, LOCAL_CFG_ROOT_PWD, LOCAL_CFG_ROOT_USER, Util\logError(), Util\logInfo(), Util\logReloadClass(), Lang\MYSQL, Win32Service\SERVER_ERROR_NORMAL, and Win32Service\SERVICE_DEMAND_START.

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

+ Here is the caller graph for this function:

◆ replaceAll()

BinMysql::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.mysql.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 ) {
159 $this->port = $value;
160 break;
162 $this->rootUser = $value;
163 break;
165 $this->rootPwd = $value;
166 break;
167 }
168 }
169
170 file_put_contents( $this->bearsamppConf, $content );
171 }

References LOCAL_CFG_PORT, LOCAL_CFG_ROOT_PWD, and LOCAL_CFG_ROOT_USER.

◆ setEnable()

BinMysql::setEnable ( $enabled,
$showWindow = false )

Enables or disables the MySQL module and updates the configuration.

Parameters
bool$enabledWhether to enable or disable the module.
bool$showWindowWhether to show a message box with the result.

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

597 {
598 global $bearsamppConfig, $bearsamppLang, $bearsamppWinbinder;
599
600 if ( $enabled == Config::ENABLED && !is_dir( $this->currentPath ) ) {
601 Util::logDebug( $this->getName() . ' cannot be enabled because bundle ' . $this->getVersion() . ' does not exist in ' . $this->currentPath );
602 if ( $showWindow ) {
603 $bearsamppWinbinder->messageBoxError(
604 sprintf( $bearsamppLang->getValue( Lang::ENABLE_BUNDLE_NOT_EXIST ), $this->getName(), $this->getVersion(), $this->currentPath ),
605 sprintf( $bearsamppLang->getValue( Lang::ENABLE_TITLE ), $this->getName() )
606 );
607 }
608 $enabled = Config::DISABLED;
609 }
610
611 Util::logInfo( $this->getName() . ' switched to ' . ($enabled == Config::ENABLED ? 'enabled' : 'disabled') );
612 $this->enable = $enabled == Config::ENABLED;
613 $bearsamppConfig->replace( self::ROOT_CFG_ENABLE, $enabled );
614
615 $this->reload();
616 if ( $this->enable ) {
617 Util::installService( $this, $this->port, self::CMD_SYNTAX_CHECK, $showWindow );
618 }
619 else {
620 Util::removeService( $this->service, $this->name );
621 }
622 }
const DISABLED
const ENABLED
const ENABLE_TITLE
const ENABLE_BUNDLE_NOT_EXIST
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()

BinMysql::setPort ( $port)

Sets the MySQL port number and updates the configuration.

Parameters
int$portThe port number to set.

Definition at line 669 of file class.bin.mysql.php.

670 {
671 $this->replace( self::LOCAL_CFG_PORT, $port );
672 }
replace($key, $value)

References $port, and Module\replace().

Referenced by changePort().

+ Here is the caller graph for this function:

◆ setRootPwd()

BinMysql::setRootPwd ( $rootPwd)

Sets the MySQL root password and updates the configuration.

Parameters
string$rootPwdThe root password to set.

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

710 {
711 $this->replace( self::LOCAL_CFG_ROOT_PWD, $rootPwd );
712 }

References $rootPwd, and Module\replace().

Referenced by changeRootPassword().

+ Here is the caller graph for this function:

◆ setRootUser()

BinMysql::setRootUser ( $rootUser)

Sets the MySQL root username and updates the configuration.

Parameters
string$rootUserThe root username to set.

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

690 {
691 $this->replace( self::LOCAL_CFG_ROOT_USER, $rootUser );
692 }

References $rootUser, and Module\replace().

◆ setVersion()

BinMysql::setVersion ( $version)

Sets the MySQL version and reloads the configuration.

Parameters
string$versionThe version to set.

Reimplemented from Module.

Definition at line 572 of file class.bin.mysql.php.

573 {
574 global $bearsamppConfig;
575 $this->version = $version;
576 $bearsamppConfig->replace( self::ROOT_CFG_VERSION, $version );
577 $this->reload();
578 }

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

Referenced by updateConfig().

+ Here is the caller graph for this function:

◆ switchVersion()

BinMysql::switchVersion ( $version,
$showWindow = false )

Switches the MySQL version and updates the configuration.

Parameters
string$versionThe new MySQL version.
bool$showWindowWhether to show a message box with the result.
Returns
bool True if the version was switched successfully, false otherwise.

Definition at line 420 of file class.bin.mysql.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()

BinMysql::updateConfig ( $version = null,
$sub = 0,
$showWindow = false )
protected

Updates the MySQL configuration with a specific 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 message box 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.mysql.php.

437 {
438 global $bearsamppLang, $bearsamppBins, $bearsamppApps, $bearsamppWinbinder;
439
440 if ( !$this->enable ) {
441 return true;
442 }
443
444 $version = $version == null ? $this->version : $version;
445 Util::logDebug( ($sub > 0 ? str_repeat( ' ', 2 * $sub ) : '') . 'Update ' . $this->name . ' ' . $version . ' config' );
446
447 $boxTitle = sprintf( $bearsamppLang->getValue( Lang::SWITCH_VERSION_TITLE ), $this->getName(), $version );
448
449 $currentPath = str_replace( 'mysql' . $this->getVersion(), 'mysql' . $version, $this->getCurrentPath() );
450 $conf = str_replace( 'mysql' . $this->getVersion(), 'mysql' . $version, $this->getConf() );
451 $bearsamppConf = str_replace( 'mysql' . $this->getVersion(), 'mysql' . $version, $this->bearsamppConf );
452
453 if ( $this->version != $version ) {
454 $this->initData( $currentPath, $version );
455 }
456
457 if ( !file_exists( $conf ) || !file_exists( $bearsamppConf ) ) {
458 Util::logError( 'bearsampp config files not found for ' . $this->getName() . ' ' . $version );
459 if ( $showWindow ) {
460 $bearsamppWinbinder->messageBoxError(
461 sprintf( $bearsamppLang->getValue( Lang::BEARSAMPP_CONF_NOT_FOUND_ERROR ), $this->getName() . ' ' . $version ),
462 $boxTitle
463 );
464 }
465
466 return false;
467 }
468
469 $bearsamppConfRaw = parse_ini_file( $bearsamppConf );
470 if ( $bearsamppConfRaw === false || !isset( $bearsamppConfRaw[self::ROOT_CFG_VERSION] ) || $bearsamppConfRaw[self::ROOT_CFG_VERSION] != $version ) {
471 Util::logError( 'bearsampp config file malformed for ' . $this->getName() . ' ' . $version );
472 if ( $showWindow ) {
473 $bearsamppWinbinder->messageBoxError(
474 sprintf( $bearsamppLang->getValue( Lang::BEARSAMPP_CONF_MALFORMED_ERROR ), $this->getName() . ' ' . $version ),
475 $boxTitle
476 );
477 }
478
479 return false;
480 }
481
482 // bearsampp.conf
483 $this->setVersion( $version );
484
485 // conf
486 Util::replaceInFile( $this->getConf(), array(
487 '/^port(.*?)=(.*?)(\d+)/' => 'port = ' . $this->port
488 ) );
489
490 // phpmyadmin
491 $bearsamppApps->getPhpmyadmin()->update( $sub + 1 );
492
493 // adminer
494 $bearsamppApps->getAdminer()->update( $sub + 1 );
495
496 // php
497 $bearsamppBins->getPhp()->update( $sub + 1 );
498
499 return true;
500 }
global $bearsamppBins
setVersion($version)
initData($path=null, $version=null)
const BEARSAMPP_CONF_NOT_FOUND_ERROR
const SWITCH_VERSION_TITLE
const BEARSAMPP_CONF_MALFORMED_ERROR
static replaceInFile($path, $replaceList)

References $bearsamppBins, Module\$bearsamppConf, Module\$bearsamppConfRaw, $bearsamppLang, $conf, Module\$currentPath, Module\$version, Lang\BEARSAMPP_CONF_MALFORMED_ERROR, Lang\BEARSAMPP_CONF_NOT_FOUND_ERROR, getConf(), Module\getCurrentPath(), Module\getName(), Module\getVersion(), initData(), Util\logDebug(), Util\logError(), Util\replaceInFile(), setVersion(), and Lang\SWITCH_VERSION_TITLE.

Referenced by switchVersion().

+ Here is the caller graph for this function:

Field Documentation

◆ $admin

BinMysql::$admin
private

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

Referenced by getAdmin().

◆ $cliExe

BinMysql::$cliExe
private

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

Referenced by getCliExe().

◆ $conf

BinMysql::$conf
private

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

Referenced by getConf(), and updateConfig().

◆ $errorLog

BinMysql::$errorLog
private

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

Referenced by getErrorLog().

◆ $exe

BinMysql::$exe
private

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

Referenced by getExe().

◆ $port

BinMysql::$port
private

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

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

◆ $rootPwd

BinMysql::$rootPwd
private

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

Referenced by getRootPwd(), and setRootPwd().

◆ $rootUser

BinMysql::$rootUser
private

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

Referenced by getRootUser(), and setRootUser().

◆ $service

BinMysql::$service
private

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

Referenced by getService().

◆ CMD_SYNTAX_CHECK

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

◆ CMD_VARIABLES

const BinMysql::CMD_VARIABLES = 'variables'

◆ CMD_VERSION

const BinMysql::CMD_VERSION = '--version'

◆ LOCAL_CFG_ADMIN

const BinMysql::LOCAL_CFG_ADMIN = 'mysqlAdmin'

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

Referenced by reload().

◆ LOCAL_CFG_CLI_EXE

const BinMysql::LOCAL_CFG_CLI_EXE = 'mysqlCliExe'

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

Referenced by reload().

◆ LOCAL_CFG_CONF

const BinMysql::LOCAL_CFG_CONF = 'mysqlConf'

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

Referenced by reload().

◆ LOCAL_CFG_EXE

const BinMysql::LOCAL_CFG_EXE = 'mysqlExe'

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

Referenced by reload().

◆ LOCAL_CFG_PORT

const BinMysql::LOCAL_CFG_PORT = 'mysqlPort'

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

Referenced by reload(), and replaceAll().

◆ LOCAL_CFG_ROOT_PWD

const BinMysql::LOCAL_CFG_ROOT_PWD = 'mysqlRootPwd'

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

Referenced by reload(), and replaceAll().

◆ LOCAL_CFG_ROOT_USER

const BinMysql::LOCAL_CFG_ROOT_USER = 'mysqlRootUser'

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

Referenced by reload(), and replaceAll().

◆ ROOT_CFG_ENABLE

const BinMysql::ROOT_CFG_ENABLE = 'mysqlEnable'

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

◆ ROOT_CFG_VERSION

const BinMysql::ROOT_CFG_VERSION = 'mysqlVersion'

Definition at line 21 of file class.bin.mysql.php.

◆ SERVICE_NAME


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