Bearsampp 2026.9.23
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

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

142 {
143 Log::initClass($this);
144 $this->reload($id, $type);
145 }
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 293 of file class.bin.postgresql.php.

294 {
295 global $bearsamppWinbinder;
296
297 if (!Util::isValidPort($port)) {
298 Log::error($this->getName() . ' port not valid: ' . $port);
299
300 return false;
301 }
302
303 $port = intval($port);
304 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
305
306 $isPortInUse = ServiceHelper::isPortInUse($port);
307 if (!$checkUsed || $isPortInUse === false) {
308 // bearsampp.conf
309 $this->setPort($port);
310 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
311
312 // conf
313 $this->update();
314 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
315
316 return true;
317 }
318
319 Log::debug($this->getName() . ' port in used: ' . $port . ' - ' . $isPortInUse);
320
321 return $isPortInUse;
322 }
static debug($data, $file=null)
static error($data, $file=null)
update($sub=0, $showWindow=false)
static isPortInUse($port)
static isValidPort($port)

References $port, Log\debug(), Log\error(), Module\getName(), ServiceHelper\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 411 of file class.bin.postgresql.php.

412 {
413 global $bearsamppWinbinder;
414 $error = null;
415
416 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
417 $dbLink = pg_connect('host=' . APP_LOCALHOST . ' port=' . $this->port . ' user=' . $this->rootUser . ' password=' . $currentPwd);
418
419 if (!$dbLink) {
420 $error = error_get_last()['message'];
421 }
422
423 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
424 $pgr = pg_query_params($dbLink, 'SELECT quote_ident($1)', array(pg_escape_string($this->rootUser)));
425 list($quoted_user) = pg_fetch_array($pgr);
426 $password = pg_escape_string($newPwd);
427 $result = pg_query($dbLink, "ALTER USER $quoted_user WITH PASSWORD '$password'");
428 if (empty($error) && !$result) {
429 $error = pg_last_error($dbLink);
430 }
431
432 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
433 if ($dbLink) {
434 pg_close($dbLink);
435 }
436
437 if (!empty($error)) {
438 return $error;
439 }
440
441 // bearsampp.conf
442 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
443 $this->setRootPwd($newPwd);
444
445 // conf
446 $this->update();
447 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
448
449 return true;
450 }
$result
const APP_LOCALHOST
Definition root.php:21

References $result, APP_LOCALHOST, 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 the port is used by PostgreSQL, false otherwise.

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

333 {
334 global $bearsamppLang, $bearsamppWinbinder;
335 $boxTitle = sprintf($bearsamppLang->getValue(Lang::CHECK_PORT_TITLE), $this->getName(), $port);
336
337 if (!Util::isValidPort($port)) {
338 Log::error($this->getName() . ' port not valid: ' . $port);
339
340 return false;
341 }
342
343 $dbLink = @pg_connect('host=' . APP_LOCALHOST . " port=$port user={$this->rootUser} password={$this->rootPwd}");
344 if (!$dbLink) {
345 $lastError = error_get_last();
346 $errorMsg = $lastError ? $lastError['message'] : 'Unknown error';
347 Log::debug($this->getName() . ' connection failed: ' . $errorMsg);
348
349 return $this->handleNonPostgresUsage($port, $showWindow, $boxTitle);
350 }
351
352 // Verify active PostgreSQL connection
353 $connectionStatus = pg_connection_status($dbLink);
354 $isPostgres = $connectionStatus === PGSQL_CONNECTION_OK;
355 pg_close($dbLink);
356
357 if ($isPostgres) {
358 Log::debug($this->getName() . " port $port is used by PostgreSQL");
359 if ($showWindow) {
360 $bearsamppWinbinder->messageBoxInfo(
361 sprintf($bearsamppLang->getValue(Lang::PORT_USED_BY), $port, 'PostgreSQL'),
362 $boxTitle
363 );
364 }
365
366 return true;
367 }
368
369 return $this->handleNonPostgresUsage($port, $showWindow, $boxTitle);
370 }
global $bearsamppLang
handleNonPostgresUsage($port, $showWindow, $boxTitle)
const CHECK_PORT_TITLE
const PORT_USED_BY

References $bearsamppLang, $port, APP_LOCALHOST, 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 460 of file class.bin.postgresql.php.

461 {
462 global $bearsamppWinbinder;
463 $currentPwd = $currentPwd == null ? $this->rootPwd : $currentPwd;
464 $error = null;
465
466 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
467 $dbLink = pg_connect('host=' . APP_LOCALHOST . ' port=' . $this->port . ' user=' . $this->rootUser . ' password=' . $currentPwd);
468 if (!$dbLink) {
469 $error = error_get_last()['message'];
470 }
471
472 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
473 if ($dbLink) {
474 pg_close($dbLink);
475 }
476
477 if (!empty($error)) {
478 return $error;
479 }
480
481 return true;
482 }

References APP_LOCALHOST.

◆ getCliExe()

getCliExe ( )

Gets the path to the PostgreSQL command line interface executable.

Returns
string The path to the CLI executable.

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

725 {
726 return $this->cliExe;
727 }

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

629 {
630 $result = null;
631
632 $bin = $this->getCliExe();
633 if (file_exists($bin)) {
634 $tmpResult = Batch::exec('postgresqlGetCmdLineOutput', '"' . $bin . '" ' . $cmd);
635 if ($tmpResult !== false && is_array($tmpResult)) {
636 $result = trim(str_replace($bin, '', implode(PHP_EOL, $tmpResult)));
637 }
638 }
639
640 return $result;
641 }
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 754 of file class.bin.postgresql.php.

755 {
756 return $this->conf;
757 }

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

715 {
716 return $this->ctlExe;
717 }

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

745 {
746 return $this->dumpAllExe;
747 }

References $dumpAllExe.

◆ getDumpExe()

getDumpExe ( )

Gets the path to the PostgreSQL dump executable.

Returns
string The path to the dump executable.

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

735 {
736 return $this->dumpExe;
737 }

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

705 {
706 return $this->errorLog;
707 }

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

765 {
766 return $this->hbaConf;
767 }

References $hbaConf.

◆ getPort()

getPort ( )

Gets the port number used by PostgreSQL.

Returns
int The port number.

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

775 {
776 return $this->port;
777 }

References $port.

◆ getRootPwd()

getRootPwd ( )

Gets the root password for PostgreSQL.

Returns
string The root password.

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

815 {
816 return $this->rootPwd;
817 }

References $rootPwd.

◆ getRootUser()

getRootUser ( )

Gets the root user for PostgreSQL.

Returns
string The root user.

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

795 {
796 return $this->rootUser;
797 }

References $rootUser.

◆ getService()

getService ( )

Gets the service object for PostgreSQL.

Returns
Win32Service The service object.

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

662 {
663 return $this->service;
664 }

References $service.

◆ handleNonPostgresUsage()

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

Handles non-PostgreSQL port usage scenarios

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

376 {
377 global $bearsamppLang, $bearsamppWinbinder;
378
380 Log::debug($this->getName() . " port $port used by non-PostgreSQL service");
381 if ($showWindow) {
382 $bearsamppWinbinder->messageBoxWarning(
384 $boxTitle
385 );
386 }
387
388 return false;
389 }
390
391 Log::debug($this->getName() . " port $port not in use");
392 if ($showWindow) {
393 $bearsamppWinbinder->messageBoxError(
394 sprintf($bearsamppLang->getValue(Lang::PORT_NOT_USED), $port),
395 $boxTitle
396 );
397 }
398
399 return false;
400 }
const PORT_NOT_USED
const PORT_USED_BY_ANOTHER_DBMS

References $bearsamppLang, $port, Log\debug(), Module\getName(), ServiceHelper\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 573 of file class.bin.postgresql.php.

574 {
575 $path = $path != null ? $path : Path::getModuleCurrentPath($this);
576
577 if (file_exists($path . '/data')) {
578 // Even if it exists, ensure placeholders are replaced in the whole folder
579 $filesToScan = Util::getFilesToScan(array(
580 array(
581 'path' => $path,
582 'includes' => array('.conf', '.bat', '.ber'),
583 'recursive' => true
584 )
585 ));
586 if (!empty($filesToScan)) {
587 Path::changePath($filesToScan);
588 }
589
590 return;
591 }
592
594
595 // Replace placeholders in the newly created data directory and the whole version folder
596 $filesToScan = Util::getFilesToScan(array(
597 array(
598 'path' => $path,
599 'includes' => array('.conf', '.bat', '.ber'),
600 'recursive' => true
601 )
602 ));
603 if (!empty($filesToScan)) {
604 Path::changePath($filesToScan);
605 }
606 }
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 611 of file class.bin.postgresql.php.

612 {
613 Util::replaceInFile($this->conf, array(
614 '/^port(.*?)=(.*?)(\d+)/' => 'port = ' . $this->port
615 ));
616 Util::replaceInFile($this->altConf, array(
617 '/^port(.*?)=(.*?)(\d+)/' => 'port = ' . $this->port
618 ));
619 }
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 153 of file class.bin.postgresql.php.

154 {
156 Log::reloadClass($this);
157
158 $this->name = $bearsamppLang->getValue(Lang::POSTGRESQL);
159 $this->version = $bearsamppConfig->getRaw(self::ROOT_CFG_VERSION);
160 parent::reload($id, $type);
161
162 $this->enable = $this->enable && $bearsamppConfig->getRaw(self::ROOT_CFG_ENABLE);
163 $this->service = new Win32Service(self::SERVICE_NAME);
164 $this->errorLog = Path::getLogsPath() . '/postgresql.log';
165
166 if ($this->bearsamppConfRaw !== false) {
167 $this->ctlExe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CTL_EXE];
168 $this->cliExe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CLI_EXE];
169 $this->dumpExe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_DUMP_EXE];
170 $this->dumpAllExe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_DUMP_ALL_EXE];
171 $this->conf = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CONF];
172 $this->hbaConf = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_HBA_CONF];
173 $this->altConf = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_ALT_CONF];
174 $this->altHbaConf = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_ALT_HBA_CONF];
175 $this->port = $this->bearsamppConfRaw[self::LOCAL_CFG_PORT];
176 $this->rootUser = isset($this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_USER]) ? $this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_USER] : 'postgres';
177 $this->rootPwd = isset($this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_PWD]) ? $this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_PWD] : '';
178 }
179
180 if (!$this->enable) {
181 Log::info($this->name . ' is not enabled!');
182
183 return;
184 }
185 if (!is_dir($this->currentPath)) {
186 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->currentPath));
187
188 return;
189 }
190 if (!is_dir($this->symlinkPath)) {
191 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->symlinkPath));
192
193 return;
194 }
195 if (!is_file($this->bearsamppConf)) {
196 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->bearsamppConf));
197
198 return;
199 }
200 if (!file_exists($this->conf)) {
201 $this->conf = $this->altConf;
202 }
203 if (!file_exists($this->hbaConf)) {
204 $this->hbaConf = $this->altHbaConf;
205 }
206
207 if (!is_file($this->ctlExe)) {
208 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->ctlExe));
209
210 return;
211 }
212 if (!is_file($this->cliExe)) {
213 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->cliExe));
214
215 return;
216 }
217 if (!is_file($this->dumpExe)) {
218 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->dumpExe));
219
220 return;
221 }
222 if (!is_file($this->dumpAllExe)) {
223 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->dumpAllExe));
224
225 return;
226 }
227 if (!is_file($this->conf)) {
228 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->conf));
229
230 return;
231 }
232 if (!is_file($this->hbaConf)) {
233 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->hbaConf));
234
235 return;
236 }
237 if (!is_numeric($this->port) || $this->port <= 0) {
238 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_INVALID_PARAMETER), self::LOCAL_CFG_PORT, $this->port));
239
240 return;
241 }
242 if (empty($this->rootUser)) {
243 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_INVALID_PARAMETER), self::LOCAL_CFG_ROOT_USER, $this->rootUser));
244
245 return;
246 }
247
248 $this->service->setDisplayName(APP_TITLE . ' ' . $this->getName());
249 $this->service->setBinPath($this->ctlExe);
250 $this->service->setStartType(Win32Service::SERVICE_DEMAND_START);
251 $this->service->setErrorControl(Win32Service::SERVER_ERROR_NORMAL);
252 }
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:46
const APP_TITLE
Definition root.php:19

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

260 {
261 $content = file_get_contents($this->bearsamppConf);
262
263 foreach ($params as $key => $value) {
264 $content = preg_replace('|' . $key . ' = .*|', $key . ' = ' . '"' . $value . '"', $content);
265 $this->bearsamppConfRaw[$key] = $value;
266 switch ($key) {
267 case self::LOCAL_CFG_PORT:
268 $this->port = $value;
269 break;
270 case self::LOCAL_CFG_ROOT_USER:
271 $this->rootUser = $value;
272 break;
273 case self::LOCAL_CFG_ROOT_PWD:
274 $this->rootPwd = $value;
275 break;
276 }
277 }
278
279 file_put_contents($this->bearsamppConf, $content);
280
281 self::invalidateConfigCacheForPath($this->bearsamppConf);
282 }
static invalidateConfigCacheForPath($sourcePath)

References Module\invalidateConfigCacheForPath().

Here is the call graph for this function:

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

673 {
674 global $bearsamppConfig, $bearsamppLang, $bearsamppWinbinder;
675
676 if ($enabled == Config::ENABLED && !is_dir($this->currentPath)) {
677 Log::debug($this->getName() . ' cannot be enabled because bundle ' . $this->getVersion() . ' does not exist in ' . $this->currentPath);
678 if ($showWindow) {
679 $bearsamppWinbinder->messageBoxError(
680 sprintf($bearsamppLang->getValue(Lang::ENABLE_BUNDLE_NOT_EXIST), $this->getName(), $this->getVersion(), $this->currentPath),
681 sprintf($bearsamppLang->getValue(Lang::ENABLE_TITLE), $this->getName())
682 );
683 }
684 $enabled = Config::DISABLED;
685 }
686
687 Log::info($this->getName() . ' switched to ' . ($enabled == Config::ENABLED ? 'enabled' : 'disabled'));
688 $this->enable = $enabled == Config::ENABLED;
689 $bearsamppConfig->replace(self::ROOT_CFG_ENABLE, $enabled);
690
691 $this->reload();
692 if ($this->enable) {
693 ServiceHelper::installService($this, $this->port, null, $showWindow);
694 } else {
695 ServiceHelper::removeService($this->service, $this->name);
696 }
697 }
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(), ServiceHelper\installService(), reload(), and ServiceHelper\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 784 of file class.bin.postgresql.php.

785 {
786 $this->replace(self::LOCAL_CFG_PORT, $port);
787 }
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 824 of file class.bin.postgresql.php.

825 {
826 $this->replace(self::LOCAL_CFG_ROOT_PWD, $rootPwd);
827 }

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

805 {
806 $this->replace(self::LOCAL_CFG_ROOT_USER, $rootUser);
807 }

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

649 {
650 global $bearsamppConfig;
651 $this->version = $version;
652 $bearsamppConfig->replace(self::ROOT_CFG_VERSION, $version);
653 $this->reload();
654 }

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

493 {
494 Log::debug('Switch ' . $this->name . ' version to ' . $version);
495
496 return $this->updateConfig($version, 0, $showWindow);
497 }
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 508 of file class.bin.postgresql.php.

509 {
510 global $bearsamppLang, $bearsamppApps, $bearsamppWinbinder;
511
512 if (!$this->enable) {
513 return true;
514 }
515
516 $version = $version == null ? $this->version : $version;
517 Log::debug(($sub > 0 ? str_repeat(' ', 2 * $sub) : '') . 'Update ' . $this->name . ' ' . $version . ' config');
518
519 $boxTitle = sprintf($bearsamppLang->getValue(Lang::SWITCH_VERSION_TITLE), $this->getName(), $version);
520
521 $currentPath = str_replace('postgresql' . $this->getVersion(), 'postgresql' . $version, Path::getModuleCurrentPath($this));
522 $conf = str_replace('postgresql' . $this->getVersion(), 'postgresql' . $version, $this->getConf());
523 $bearsamppConf = str_replace('postgresql' . $this->getVersion(), 'postgresql' . $version, $this->bearsamppConf);
524
525 if ($this->version != $version) {
526 $this->initData($currentPath);
527 }
528
529 if (!file_exists($conf) || !file_exists($bearsamppConf)) {
530 Log::error('bearsampp config files not found for ' . $this->getName() . ' ' . $version);
531 if ($showWindow) {
532 $bearsamppWinbinder->messageBoxError(
533 sprintf($bearsamppLang->getValue(Lang::BEARSAMPP_CONF_NOT_FOUND_ERROR), $this->getName() . ' ' . $version),
534 $boxTitle
535 );
536 }
537
538 return false;
539 }
540
541 $bearsamppConfRaw = parse_ini_file($bearsamppConf);
542 if ($bearsamppConfRaw === false || !isset($bearsamppConfRaw[self::ROOT_CFG_VERSION]) || $bearsamppConfRaw[self::ROOT_CFG_VERSION] != $version) {
543 Log::error('bearsampp config file malformed for ' . $this->getName() . ' ' . $version);
544 if ($showWindow) {
545 $bearsamppWinbinder->messageBoxError(
546 sprintf($bearsamppLang->getValue(Lang::BEARSAMPP_CONF_MALFORMED_ERROR), $this->getName() . ' ' . $version),
547 $boxTitle
548 );
549 }
550
551 return false;
552 }
553
554 // bearsampp.conf
555 $this->setVersion($version);
556
557 // conf
558 Util::replaceInFile($this->getConf(), array(
559 '/^port(.*?)=(.*?)(\d+)/' => 'port = ' . $this->port
560 ));
561
562 // phppgadmin
563 $bearsamppApps->getPhppgadmin()->update($sub + 1);
564
565 return true;
566 }
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 117 of file class.bin.postgresql.php.

Referenced by reload().

◆ $altHbaConf

$altHbaConf
private

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

Referenced by reload().

◆ $cliExe

$cliExe
private

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

Referenced by getCliExe().

◆ $conf

$conf
private

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

Referenced by getConf(), and updateConfig().

◆ $ctlExe

$ctlExe
private

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

Referenced by getCtlExe().

◆ $dumpAllExe

$dumpAllExe
private

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

Referenced by getDumpAllExe().

◆ $dumpExe

$dumpExe
private

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

Referenced by getDumpExe().

◆ $errorLog

$errorLog
private

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

Referenced by getErrorLog().

◆ $hbaConf

$hbaConf
private

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

Referenced by getHbaConf().

◆ $port

$port
private

◆ $rootPwd

$rootPwd
private

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

Referenced by getRootPwd(), and setRootPwd().

◆ $rootUser

$rootUser
private

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

Referenced by getRootUser(), and setRootUser().

◆ $service

$service
private

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

Referenced by getService().

◆ CMD_VERSION

const CMD_VERSION = '--version'

Command line option to display the PostgreSQL version.

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

Referenced by ActionDebugPostgresql\getCommandMapping(), and TplAppPostgresql\getMenuPostgresqlDebug().

◆ LOCAL_CFG_ALT_CONF

const LOCAL_CFG_ALT_CONF = 'postgresqlAltConf'

Configuration key for the PostgreSQL alternate configuration file in the local configuration.

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

◆ LOCAL_CFG_ALT_HBA_CONF

const LOCAL_CFG_ALT_HBA_CONF = 'postgresqlAltUserConf'

Configuration key for the PostgreSQL alternate HBA configuration file in the local configuration.

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

◆ LOCAL_CFG_CLI_EXE

const LOCAL_CFG_CLI_EXE = 'postgresqlCliExe'

Configuration key for the PostgreSQL CLI executable in the local configuration.

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

◆ LOCAL_CFG_CONF

const LOCAL_CFG_CONF = 'postgresqlConf'

Configuration key for the PostgreSQL configuration file in the local configuration.

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

◆ LOCAL_CFG_CTL_EXE

const LOCAL_CFG_CTL_EXE = 'postgresqlCtlExe'

Configuration key for the PostgreSQL control executable in the local configuration.

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

◆ LOCAL_CFG_DUMP_ALL_EXE

const LOCAL_CFG_DUMP_ALL_EXE = 'postgresqlDumpAllExe'

Configuration key for the PostgreSQL dump-all executable in the local configuration.

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

◆ LOCAL_CFG_DUMP_EXE

const LOCAL_CFG_DUMP_EXE = 'postgresqlDumpExe'

Configuration key for the PostgreSQL dump executable in the local configuration.

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

◆ LOCAL_CFG_HBA_CONF

const LOCAL_CFG_HBA_CONF = 'postgresqlUserConf'

Configuration key for the PostgreSQL HBA configuration file in the local configuration.

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

◆ LOCAL_CFG_PORT

const LOCAL_CFG_PORT = 'postgresqlPort'

Configuration key for the PostgreSQL port in the local configuration.

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

◆ LOCAL_CFG_ROOT_PWD

const LOCAL_CFG_ROOT_PWD = 'postgresqlRootPwd'

Configuration key for the PostgreSQL root password in the local configuration.

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

◆ LOCAL_CFG_ROOT_USER

const LOCAL_CFG_ROOT_USER = 'postgresqlRootUser'

Configuration key for the PostgreSQL root user in the local configuration.

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

◆ ROOT_CFG_ENABLE

const ROOT_CFG_ENABLE = 'postgresqlEnable'

Configuration key for the PostgreSQL enable flag in the root configuration.

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

◆ ROOT_CFG_VERSION

const ROOT_CFG_VERSION = 'postgresqlVersion'

Configuration key for the PostgreSQL version in the root configuration.

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

◆ SERVICE_NAME


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