Bearsampp 2026.7.11
Loading...
Searching...
No Matches
BinPostgresql Class Reference
Inheritance diagram for BinPostgresql:
Collaboration diagram for BinPostgresql:

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)
 getCliExe ()
 getCmdLineOutput ($cmd)
 getConf ()
 getCtlExe ()
 getDumpAllExe ()
 getDumpExe ()
 getErrorLog ()
 getHbaConf ()
 getPort ()
 getRootPwd ()
 getRootUser ()
 getService ()
 initData ($path=null)
 rebuildConf ()
 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_VERSION = '--version'
const LOCAL_CFG_ALT_CONF = 'postgresqlAltConf'
const LOCAL_CFG_ALT_HBA_CONF = 'postgresqlAltUserConf'
const LOCAL_CFG_CLI_EXE = 'postgresqlCliExe'
const LOCAL_CFG_CONF = 'postgresqlConf'
const LOCAL_CFG_CTL_EXE = 'postgresqlCtlExe'
const LOCAL_CFG_DUMP_ALL_EXE = 'postgresqlDumpAllExe'
const LOCAL_CFG_DUMP_EXE = 'postgresqlDumpExe'
const LOCAL_CFG_HBA_CONF = 'postgresqlUserConf'
const LOCAL_CFG_PORT = 'postgresqlPort'
const LOCAL_CFG_ROOT_PWD = 'postgresqlRootPwd'
const LOCAL_CFG_ROOT_USER = 'postgresqlRootUser'
const ROOT_CFG_ENABLE = 'postgresqlEnable'
const ROOT_CFG_VERSION = 'postgresqlVersion'
const SERVICE_NAME = 'bearsampppostgresql'
Data Fields inherited from Module
 $currentPath
 $rootPath
 $symlinkPath
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 Member Functions

 handleNonPostgresUsage ($port, $showWindow, $boxTitle)

Private Attributes

 $altConf
 $altHbaConf
 $cliExe
 $conf
 $ctlExe
 $dumpAllExe
 $dumpExe
 $errorLog
 $hbaConf
 $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 BinPostgresql

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

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

Constructor & Destructor Documentation

◆ __construct()

__construct ( $id,
$type )

Constructor for the BinPostgresql class.

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

Definition at line 57 of file class.bin.postgresql.php.

58 {
59 Log::initClass( $this );
60 $this->reload( $id, $type );
61 }
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 used by PostgreSQL.

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 207 of file class.bin.postgresql.php.

208 {
209 global $bearsamppWinbinder;
210
211 if ( !Util::isValidPort( $port ) ) {
212 Log::error( $this->getName() . ' port not valid: ' . $port );
213
214 return false;
215 }
216
217 $port = intval( $port );
218 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
219
220 $isPortInUse = Util::isPortInUse( $port );
221 if ( !$checkUsed || $isPortInUse === false ) {
222 // bearsampp.conf
223 $this->setPort( $port );
224 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
225
226 // conf
227 $this->update();
228 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
229
230 return true;
231 }
232
233 Log::debug( $this->getName() . ' port in used: ' . $port . ' - ' . $isPortInUse );
234
235 return $isPortInUse;
236 }
static debug($data, $file=null)
static error($data, $file=null)
update($sub=0, $showWindow=false)
static isValidPort($port)
static isPortInUse($port)

References $port, Log\debug(), Log\error(), Module\getName(), Util\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 PostgreSQL.

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 317 of file class.bin.postgresql.php.

318 {
319 global $bearsamppWinbinder;
320 $error = null;
321
322 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
323 $dbLink = pg_connect( 'host=127.0.0.1 port=' . $this->port . ' user=' . $this->rootUser . ' password=' . $currentPwd );
324
325 if ( !$dbLink ) {
326 $error = error_get_last()['message'];
327 }
328
329 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
330 $pgr = pg_query_params( $dbLink, 'SELECT quote_ident($1)', array(pg_escape_string( $this->rootUser )) );
331 list( $quoted_user ) = pg_fetch_array( $pgr );
332 $password = pg_escape_string( $newPwd );
333 $result = pg_query( $dbLink, "ALTER USER $quoted_user WITH PASSWORD '$password'" );
334 if ( empty( $error ) && !$result ) {
335 $error = pg_last_error( $dbLink );
336 }
337
338 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
339 if ( $dbLink ) {
340 pg_close( $dbLink );
341 }
342
343 if ( !empty( $error ) ) {
344 return $error;
345 }
346
347 // bearsampp.conf
348 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
349 $this->setRootPwd( $newPwd );
350
351 // conf
352 $this->update();
353 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
354
355 return true;
356 }
$result

References $result, setRootPwd(), and Module\update().

Here is the call graph for this function:

◆ checkPort()

checkPort ( $port,
$showWindow = false )

Checks if the specified port is being used by PostgreSQL

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

Definition at line 244 of file class.bin.postgresql.php.

245 {
246 global $bearsamppLang, $bearsamppWinbinder;
247 $boxTitle = sprintf($bearsamppLang->getValue(Lang::CHECK_PORT_TITLE), $this->getName(), $port);
248
249 if (!Util::isValidPort($port)) {
250 Log::error($this->getName() . ' port not valid: ' . $port);
251 return false;
252 }
253
254 $dbLink = @pg_connect("host=127.0.0.1 port=$port user={$this->rootUser} password={$this->rootPwd}");
255 if (!$dbLink) {
256 $lastError = error_get_last();
257 $errorMsg = $lastError ? $lastError['message'] : 'Unknown error';
258 Log::debug($this->getName() . ' connection failed: ' . $errorMsg);
259 return $this->handleNonPostgresUsage($port, $showWindow, $boxTitle);
260 }
261
262 // Verify active PostgreSQL connection
263 $connectionStatus = pg_connection_status($dbLink);
264 $isPostgres = $connectionStatus === PGSQL_CONNECTION_OK;
265 pg_close($dbLink);
266
267 if ($isPostgres) {
268 Log::debug($this->getName() . " port $port is used by PostgreSQL");
269 if ($showWindow) {
270 $bearsamppWinbinder->messageBoxInfo(
271 sprintf($bearsamppLang->getValue(Lang::PORT_USED_BY), $port, 'PostgreSQL'),
272 $boxTitle
273 );
274 }
275 return true;
276 }
277
278 return $this->handleNonPostgresUsage($port, $showWindow, $boxTitle);
279 }
global $bearsamppLang
handleNonPostgresUsage($port, $showWindow, $boxTitle)
const CHECK_PORT_TITLE
const PORT_USED_BY

References $bearsamppLang, $port, Lang\CHECK_PORT_TITLE, Log\debug(), Log\error(), Module\getName(), handleNonPostgresUsage(), Util\isValidPort(), and Lang\PORT_USED_BY.

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 366 of file class.bin.postgresql.php.

367 {
368 global $bearsamppWinbinder;
369 $currentPwd = $currentPwd == null ? $this->rootPwd : $currentPwd;
370 $error = null;
371
372 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
373 $dbLink = pg_connect( 'host=127.0.0.1 port=' . $this->port . ' user=' . $this->rootUser . ' password=' . $currentPwd );
374 if ( !$dbLink ) {
375 $error = error_get_last()['message'];
376 }
377
378 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
379 if ( $dbLink ) {
380 pg_close( $dbLink );
381 }
382
383 if ( !empty( $error ) ) {
384 return $error;
385 }
386
387 return true;
388 }

◆ getCliExe()

getCliExe ( )

Gets the path to the PostgreSQL command line interface executable.

Returns
string The path to the CLI executable.

Definition at line 630 of file class.bin.postgresql.php.

631 {
632 return $this->cliExe;
633 }

References $cliExe.

Referenced by getCmdLineOutput().

Here is the caller graph for this function:

◆ getCmdLineOutput()

getCmdLineOutput ( $cmd)

Executes a PostgreSQL command line instruction and returns the output.

Parameters
string$cmdThe command to execute.
Returns
string|null The output of the command, or null if the command failed.

Definition at line 533 of file class.bin.postgresql.php.

534 {
535 $result = null;
536
537 $bin = $this->getCliExe();
538 if ( file_exists( $bin ) ) {
539 $tmpResult = Batch::exec( 'postgresqlGetCmdLineOutput', '"' . $bin . '" ' . $cmd );
540 if ( $tmpResult !== false && is_array( $tmpResult ) ) {
541 $result = trim( str_replace( $bin, '', implode( PHP_EOL, $tmpResult ) ) );
542 }
543 }
544
545 return $result;
546 }
static exec($basename, $content, $timeout=true, $catchOutput=true, $standalone=false, $silent=true, $rebuild=true)

References $result, Batch\exec(), and getCliExe().

Here is the call graph for this function:

◆ getConf()

getConf ( )

Gets the path to the PostgreSQL configuration file.

Returns
string The path to the configuration file.

Definition at line 660 of file class.bin.postgresql.php.

661 {
662 return $this->conf;
663 }

References $conf.

Referenced by updateConfig().

Here is the caller graph for this function:

◆ getCtlExe()

getCtlExe ( )

Gets the path to the PostgreSQL control executable.

Returns
string The path to the control executable.

Definition at line 620 of file class.bin.postgresql.php.

621 {
622 return $this->ctlExe;
623 }

References $ctlExe.

◆ getDumpAllExe()

getDumpAllExe ( )

Gets the path to the PostgreSQL dump all executable.

Returns
string The path to the dump all executable.

Definition at line 650 of file class.bin.postgresql.php.

651 {
652 return $this->dumpAllExe;
653 }

References $dumpAllExe.

◆ getDumpExe()

getDumpExe ( )

Gets the path to the PostgreSQL dump executable.

Returns
string The path to the dump executable.

Definition at line 640 of file class.bin.postgresql.php.

641 {
642 return $this->dumpExe;
643 }

References $dumpExe.

◆ getErrorLog()

getErrorLog ( )

Gets the path to the PostgreSQL error log file.

Returns
string The path to the error log file.

Definition at line 610 of file class.bin.postgresql.php.

611 {
612 return $this->errorLog;
613 }

References $errorLog.

◆ getHbaConf()

getHbaConf ( )

Gets the path to the PostgreSQL host-based authentication configuration file.

Returns
string The path to the HBA configuration file.

Definition at line 670 of file class.bin.postgresql.php.

671 {
672 return $this->hbaConf;
673 }

References $hbaConf.

◆ getPort()

getPort ( )

Gets the port number used by PostgreSQL.

Returns
int The port number.

Definition at line 680 of file class.bin.postgresql.php.

681 {
682 return $this->port;
683 }

References $port.

◆ getRootPwd()

getRootPwd ( )

Gets the root password for PostgreSQL.

Returns
string The root password.

Definition at line 720 of file class.bin.postgresql.php.

721 {
722 return $this->rootPwd;
723 }

References $rootPwd.

◆ getRootUser()

getRootUser ( )

Gets the root user for PostgreSQL.

Returns
string The root user.

Definition at line 700 of file class.bin.postgresql.php.

701 {
702 return $this->rootUser;
703 }

References $rootUser.

◆ getService()

getService ( )

Gets the service object for PostgreSQL.

Returns
Win32Service The service object.

Definition at line 566 of file class.bin.postgresql.php.

567 {
568 return $this->service;
569 }

References $service.

◆ handleNonPostgresUsage()

handleNonPostgresUsage ( $port,
$showWindow,
$boxTitle )
private

Handles non-PostgreSQL port usage scenarios

Definition at line 284 of file class.bin.postgresql.php.

285 {
286 global $bearsamppLang, $bearsamppWinbinder;
287
289 Log::debug($this->getName() . " port $port used by non-PostgreSQL service");
290 if ($showWindow) {
291 $bearsamppWinbinder->messageBoxWarning(
293 $boxTitle
294 );
295 }
296 return false;
297 }
298
299 Log::debug($this->getName() . " port $port not in use");
300 if ($showWindow) {
301 $bearsamppWinbinder->messageBoxError(
302 sprintf($bearsamppLang->getValue(Lang::PORT_NOT_USED), $port),
303 $boxTitle
304 );
305 }
306 return false;
307 }
const PORT_NOT_USED
const PORT_USED_BY_ANOTHER_DBMS

References $bearsamppLang, $port, Log\debug(), Module\getName(), Util\isPortInUse(), Lang\PORT_NOT_USED, and Lang\PORT_USED_BY_ANOTHER_DBMS.

Referenced by checkPort().

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

◆ initData()

initData ( $path = null)

Initializes the data directory for PostgreSQL if it does not already exist.

Parameters
string | null$pathThe path to the PostgreSQL data directory. If null, the current path is used.

Definition at line 479 of file class.bin.postgresql.php.

480 {
481 $path = $path != null ? $path : Path::getModuleCurrentPath($this);
482
483 if ( file_exists( $path . '/data' ) ) {
484 // Even if it exists, ensure placeholders are replaced in the whole folder
485 $filesToScan = Util::getFilesToScan( array(
486 array(
487 'path' => $path,
488 'includes' => array( '.conf', '.bat', '.ber' ),
489 'recursive' => true
490 )
491 ) );
492 if ( !empty( $filesToScan ) ) {
493 Path::changePath( $filesToScan );
494 }
495 return;
496 }
497
499
500 // Replace placeholders in the newly created data directory and the whole version folder
501 $filesToScan = Util::getFilesToScan( array(
502 array(
503 'path' => $path,
504 'includes' => array( '.conf', '.bat', '.ber' ),
505 'recursive' => true
506 )
507 ) );
508 if ( !empty( $filesToScan ) ) {
509 Path::changePath( $filesToScan );
510 }
511 }
static initializePostgresql($path)
static changePath($filesToScan, $rootPath=null)
static getModuleCurrentPath($module)
static getFilesToScan($path=null, $useCache=true, $forceRefresh=false)

References Path\changePath(), Util\getFilesToScan(), Path\getModuleCurrentPath(), and Batch\initializePostgresql().

Referenced by updateConfig().

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

◆ rebuildConf()

rebuildConf ( )

Rebuilds the PostgreSQL configuration files by updating the port number.

Definition at line 516 of file class.bin.postgresql.php.

517 {
518 Util::replaceInFile( $this->conf, array(
519 '/^port(.*?)=(.*?)(\d+)/' => 'port = ' . $this->port
520 ) );
521 Util::replaceInFile( $this->altConf, array(
522 '/^port(.*?)=(.*?)(\d+)/' => 'port = ' . $this->port
523 ) );
524 }
static replaceInFile($path, $replaceList)

References Util\replaceInFile().

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 69 of file class.bin.postgresql.php.

70 {
72 Log::reloadClass( $this );
73
74 $this->name = $bearsamppLang->getValue( Lang::POSTGRESQL );
75 $this->version = $bearsamppConfig->getRaw( self::ROOT_CFG_VERSION );
76 parent::reload( $id, $type );
77
78 $this->enable = $this->enable && $bearsamppConfig->getRaw( self::ROOT_CFG_ENABLE );
79 $this->service = new Win32Service( self::SERVICE_NAME );
80 $this->errorLog = Path::getLogsPath() . '/postgresql.log';
81
82 if ( $this->bearsamppConfRaw !== false ) {
83 $this->ctlExe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CTL_EXE];
84 $this->cliExe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CLI_EXE];
85 $this->dumpExe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_DUMP_EXE];
86 $this->dumpAllExe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_DUMP_ALL_EXE];
87 $this->conf = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CONF];
88 $this->hbaConf = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_HBA_CONF];
89 $this->altConf = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_ALT_CONF];
90 $this->altHbaConf = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_ALT_HBA_CONF];
91 $this->port = $this->bearsamppConfRaw[self::LOCAL_CFG_PORT];
92 $this->rootUser = isset( $this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_USER] ) ? $this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_USER] : 'postgres';
93 $this->rootPwd = isset( $this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_PWD] ) ? $this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_PWD] : '';
94 }
95
96 if ( !$this->enable ) {
97 Log::info( $this->name . ' is not enabled!' );
98
99 return;
100 }
101 if ( !is_dir( $this->currentPath ) ) {
102 Log::error( sprintf( $bearsamppLang->getValue( Lang::ERROR_FILE_NOT_FOUND ), $this->name . ' ' . $this->version, $this->currentPath ) );
103
104 return;
105 }
106 if ( !is_dir( $this->symlinkPath ) ) {
107 Log::error( sprintf( $bearsamppLang->getValue( Lang::ERROR_FILE_NOT_FOUND ), $this->name . ' ' . $this->version, $this->symlinkPath ) );
108
109 return;
110 }
111 if ( !is_file( $this->bearsamppConf ) ) {
112 Log::error( sprintf( $bearsamppLang->getValue( Lang::ERROR_CONF_NOT_FOUND ), $this->name . ' ' . $this->version, $this->bearsamppConf ) );
113
114 return;
115 }
116 if ( !file_exists( $this->conf ) ) {
117 $this->conf = $this->altConf;
118 }
119 if ( !file_exists( $this->hbaConf ) ) {
120 $this->hbaConf = $this->altHbaConf;
121 }
122
123 if ( !is_file( $this->ctlExe ) ) {
124 Log::error( sprintf( $bearsamppLang->getValue( Lang::ERROR_EXE_NOT_FOUND ), $this->name . ' ' . $this->version, $this->ctlExe ) );
125
126 return;
127 }
128 if ( !is_file( $this->cliExe ) ) {
129 Log::error( sprintf( $bearsamppLang->getValue( Lang::ERROR_EXE_NOT_FOUND ), $this->name . ' ' . $this->version, $this->cliExe ) );
130
131 return;
132 }
133 if ( !is_file( $this->dumpExe ) ) {
134 Log::error( sprintf( $bearsamppLang->getValue( Lang::ERROR_EXE_NOT_FOUND ), $this->name . ' ' . $this->version, $this->dumpExe ) );
135
136 return;
137 }
138 if ( !is_file( $this->dumpAllExe ) ) {
139 Log::error( sprintf( $bearsamppLang->getValue( Lang::ERROR_EXE_NOT_FOUND ), $this->name . ' ' . $this->version, $this->dumpAllExe ) );
140
141 return;
142 }
143 if ( !is_file( $this->conf ) ) {
144 Log::error( sprintf( $bearsamppLang->getValue( Lang::ERROR_CONF_NOT_FOUND ), $this->name . ' ' . $this->version, $this->conf ) );
145
146 return;
147 }
148 if ( !is_file( $this->hbaConf ) ) {
149 Log::error( sprintf( $bearsamppLang->getValue( Lang::ERROR_CONF_NOT_FOUND ), $this->name . ' ' . $this->version, $this->hbaConf ) );
150
151 return;
152 }
153 if ( !is_numeric( $this->port ) || $this->port <= 0 ) {
154 Log::error( sprintf( $bearsamppLang->getValue( Lang::ERROR_INVALID_PARAMETER ), self::LOCAL_CFG_PORT, $this->port ) );
155
156 return;
157 }
158 if ( empty( $this->rootUser ) ) {
159 Log::error( sprintf( $bearsamppLang->getValue( Lang::ERROR_INVALID_PARAMETER ), self::LOCAL_CFG_ROOT_USER, $this->rootUser ) );
160
161 return;
162 }
163
164 $this->service->setDisplayName( APP_TITLE . ' ' . $this->getName() );
165 $this->service->setBinPath( $this->ctlExe );
166 $this->service->setStartType( Win32Service::SERVICE_DEMAND_START );
167 $this->service->setErrorControl( Win32Service::SERVER_ERROR_NORMAL );
168 }
global $bearsamppRoot
const ERROR_EXE_NOT_FOUND
const ERROR_CONF_NOT_FOUND
const POSTGRESQL
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:41
const APP_TITLE
Definition root.php:13

References $altConf, $altHbaConf, $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\getLogsPath(), Module\getName(), Log\info(), Lang\POSTGRESQL, 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 175 of file class.bin.postgresql.php.

176 {
177 $content = file_get_contents( $this->bearsamppConf );
178
179 foreach ( $params as $key => $value ) {
180 $content = preg_replace( '|' . $key . ' = .*|', $key . ' = ' . '"' . $value . '"', $content );
181 $this->bearsamppConfRaw[$key] = $value;
182 switch ( $key ) {
183 case self::LOCAL_CFG_PORT:
184 $this->port = $value;
185 break;
186 case self::LOCAL_CFG_ROOT_USER:
187 $this->rootUser = $value;
188 break;
189 case self::LOCAL_CFG_ROOT_PWD:
190 $this->rootPwd = $value;
191 break;
192 }
193 }
194
195 file_put_contents( $this->bearsamppConf, $content );
196 }

◆ setEnable()

setEnable ( $enabled,
$showWindow = false )

Enables or disables the PostgreSQL module.

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

Definition at line 577 of file class.bin.postgresql.php.

578 {
579 global $bearsamppConfig, $bearsamppLang, $bearsamppWinbinder;
580
581 if ( $enabled == Config::ENABLED && !is_dir( $this->currentPath ) ) {
582 Log::debug( $this->getName() . ' cannot be enabled because bundle ' . $this->getVersion() . ' does not exist in ' . $this->currentPath );
583 if ( $showWindow ) {
584 $bearsamppWinbinder->messageBoxError(
585 sprintf( $bearsamppLang->getValue( Lang::ENABLE_BUNDLE_NOT_EXIST ), $this->getName(), $this->getVersion(), $this->currentPath ),
586 sprintf( $bearsamppLang->getValue( Lang::ENABLE_TITLE ), $this->getName() )
587 );
588 }
589 $enabled = Config::DISABLED;
590 }
591
592 Log::info( $this->getName() . ' switched to ' . ($enabled == Config::ENABLED ? 'enabled' : 'disabled') );
593 $this->enable = $enabled == Config::ENABLED;
594 $bearsamppConfig->replace( self::ROOT_CFG_ENABLE, $enabled );
595
596 $this->reload();
597 if ( $this->enable ) {
598 Util::installService( $this, $this->port, null, $showWindow );
599 }
600 else {
601 Util::removeService( $this->service, $this->name );
602 }
603 }
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(), Util\installService(), reload(), and Util\removeService().

Here is the call graph for this function:

◆ setPort()

setPort ( $port)

Sets the port number used by PostgreSQL.

Parameters
int$portThe port number to set.

Definition at line 690 of file class.bin.postgresql.php.

691 {
692 $this->replace( self::LOCAL_CFG_PORT, $port );
693 }
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 PostgreSQL.

Parameters
string$rootPwdThe root password to set.

Definition at line 730 of file class.bin.postgresql.php.

731 {
732 $this->replace( self::LOCAL_CFG_ROOT_PWD, $rootPwd );
733 }

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 PostgreSQL.

Parameters
string$rootUserThe root user to set.

Definition at line 710 of file class.bin.postgresql.php.

711 {
712 $this->replace( self::LOCAL_CFG_ROOT_USER, $rootUser );
713 }

References $rootUser, and Module\replace().

Here is the call graph for this function:

◆ setVersion()

setVersion ( $version)

Sets the version of PostgreSQL and reloads the configuration.

Parameters
string$versionThe version to set.

Reimplemented from Module.

Definition at line 553 of file class.bin.postgresql.php.

554 {
555 global $bearsamppConfig;
556 $this->version = $version;
557 $bearsamppConfig->replace( self::ROOT_CFG_VERSION, $version );
558 $this->reload();
559 }

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 PostgreSQL version.

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

Definition at line 398 of file class.bin.postgresql.php.

399 {
400 Log::debug( 'Switch ' . $this->name . ' version to ' . $version );
401
402 return $this->updateConfig( $version, 0, $showWindow );
403 }
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 PostgreSQL configuration.

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 during the update process.
Returns
bool True if the configuration was updated successfully, false otherwise.

Reimplemented from Module.

Definition at line 414 of file class.bin.postgresql.php.

415 {
416 global $bearsamppLang, $bearsamppApps, $bearsamppWinbinder;
417
418 if ( !$this->enable ) {
419 return true;
420 }
421
422 $version = $version == null ? $this->version : $version;
423 Log::debug( ($sub > 0 ? str_repeat( ' ', 2 * $sub ) : '') . 'Update ' . $this->name . ' ' . $version . ' config' );
424
425 $boxTitle = sprintf( $bearsamppLang->getValue( Lang::SWITCH_VERSION_TITLE ), $this->getName(), $version );
426
427 $currentPath = str_replace( 'postgresql' . $this->getVersion(), 'postgresql' . $version, Path::getModuleCurrentPath($this) );
428 $conf = str_replace( 'postgresql' . $this->getVersion(), 'postgresql' . $version, $this->getConf() );
429 $bearsamppConf = str_replace( 'postgresql' . $this->getVersion(), 'postgresql' . $version, $this->bearsamppConf );
430
431 if ( $this->version != $version ) {
432 $this->initData( $currentPath );
433 }
434
435 if ( !file_exists( $conf ) || !file_exists( $bearsamppConf ) ) {
436 Log::error( 'bearsampp config files not found for ' . $this->getName() . ' ' . $version );
437 if ( $showWindow ) {
438 $bearsamppWinbinder->messageBoxError(
439 sprintf( $bearsamppLang->getValue( Lang::BEARSAMPP_CONF_NOT_FOUND_ERROR ), $this->getName() . ' ' . $version ),
440 $boxTitle
441 );
442 }
443
444 return false;
445 }
446
447 $bearsamppConfRaw = parse_ini_file( $bearsamppConf );
448 if ( $bearsamppConfRaw === false || !isset( $bearsamppConfRaw[self::ROOT_CFG_VERSION] ) || $bearsamppConfRaw[self::ROOT_CFG_VERSION] != $version ) {
449 Log::error( 'bearsampp config file malformed for ' . $this->getName() . ' ' . $version );
450 if ( $showWindow ) {
451 $bearsamppWinbinder->messageBoxError(
452 sprintf( $bearsamppLang->getValue( Lang::BEARSAMPP_CONF_MALFORMED_ERROR ), $this->getName() . ' ' . $version ),
453 $boxTitle
454 );
455 }
456
457 return false;
458 }
459
460 // bearsampp.conf
461 $this->setVersion( $version );
462
463 // conf
464 Util::replaceInFile( $this->getConf(), array(
465 '/^port(.*?)=(.*?)(\d+)/' => 'port = ' . $this->port
466 ) );
467
468 // phppgadmin
469 $bearsamppApps->getPhppgadmin()->update( $sub + 1 );
470
471 return true;
472 }
const BEARSAMPP_CONF_MALFORMED_ERROR
const BEARSAMPP_CONF_NOT_FOUND_ERROR
const SWITCH_VERSION_TITLE

References Module\$bearsamppConf, Module\$bearsamppConfRaw, $bearsamppLang, $conf, Module\$currentPath, Module\$version, Lang\BEARSAMPP_CONF_MALFORMED_ERROR, Lang\BEARSAMPP_CONF_NOT_FOUND_ERROR, Log\debug(), Log\error(), getConf(), Path\getModuleCurrentPath(), Module\getName(), Module\getVersion(), initData(), 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

◆ $altConf

$altConf
private

Definition at line 45 of file class.bin.postgresql.php.

Referenced by reload().

◆ $altHbaConf

$altHbaConf
private

Definition at line 46 of file class.bin.postgresql.php.

Referenced by reload().

◆ $cliExe

$cliExe
private

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

Referenced by getCliExe().

◆ $conf

$conf
private

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

Referenced by getConf(), and updateConfig().

◆ $ctlExe

$ctlExe
private

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

Referenced by getCtlExe().

◆ $dumpAllExe

$dumpAllExe
private

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

Referenced by getDumpAllExe().

◆ $dumpExe

$dumpExe
private

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

Referenced by getDumpExe().

◆ $errorLog

$errorLog
private

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

Referenced by getErrorLog().

◆ $hbaConf

$hbaConf
private

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

Referenced by getHbaConf().

◆ $port

$port
private

◆ $rootPwd

$rootPwd
private

Definition at line 49 of file class.bin.postgresql.php.

Referenced by getRootPwd(), and setRootPwd().

◆ $rootUser

$rootUser
private

Definition at line 48 of file class.bin.postgresql.php.

Referenced by getRootUser(), and setRootUser().

◆ $service

$service
private

Definition at line 37 of file class.bin.postgresql.php.

Referenced by getService().

◆ CMD_VERSION

const CMD_VERSION = '--version'

◆ LOCAL_CFG_ALT_CONF

const LOCAL_CFG_ALT_CONF = 'postgresqlAltConf'

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

◆ LOCAL_CFG_ALT_HBA_CONF

const LOCAL_CFG_ALT_HBA_CONF = 'postgresqlAltUserConf'

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

◆ LOCAL_CFG_CLI_EXE

const LOCAL_CFG_CLI_EXE = 'postgresqlCliExe'

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

◆ LOCAL_CFG_CONF

const LOCAL_CFG_CONF = 'postgresqlConf'

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

◆ LOCAL_CFG_CTL_EXE

const LOCAL_CFG_CTL_EXE = 'postgresqlCtlExe'

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

◆ LOCAL_CFG_DUMP_ALL_EXE

const LOCAL_CFG_DUMP_ALL_EXE = 'postgresqlDumpAllExe'

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

◆ LOCAL_CFG_DUMP_EXE

const LOCAL_CFG_DUMP_EXE = 'postgresqlDumpExe'

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

◆ LOCAL_CFG_HBA_CONF

const LOCAL_CFG_HBA_CONF = 'postgresqlUserConf'

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

◆ LOCAL_CFG_PORT

const LOCAL_CFG_PORT = 'postgresqlPort'

Definition at line 31 of file class.bin.postgresql.php.

◆ LOCAL_CFG_ROOT_PWD

const LOCAL_CFG_ROOT_PWD = 'postgresqlRootPwd'

Definition at line 33 of file class.bin.postgresql.php.

◆ LOCAL_CFG_ROOT_USER

const LOCAL_CFG_ROOT_USER = 'postgresqlRootUser'

Definition at line 32 of file class.bin.postgresql.php.

◆ ROOT_CFG_ENABLE

const ROOT_CFG_ENABLE = 'postgresqlEnable'

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

◆ ROOT_CFG_VERSION

const ROOT_CFG_VERSION = 'postgresqlVersion'

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

◆ SERVICE_NAME


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