2024.8.23
Loading...
Searching...
No Matches
class.app.phppgadmin.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: Bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
10/**
11 * Class AppPhppgadmin
12 *
13 * This class represents the phpPgAdmin application module in the Bearsampp application.
14 * It handles the initialization, configuration, and management of the phpPgAdmin module.
15 */
16class AppPhppgadmin extends Module
17{
18 /**
19 * Configuration key for the phpPgAdmin version in the root configuration.
20 */
21 const ROOT_CFG_VERSION = 'phppgadminVersion';
22
23 /**
24 * Configuration key for the phpPgAdmin configuration file in the local configuration.
25 */
26 const LOCAL_CFG_CONF = 'phppgadminConf';
27
28 /**
29 * @var string The path to the phpPgAdmin configuration file.
30 */
31 private $conf;
32
33 /**
34 * Constructor for the AppPhppgadmin class.
35 *
36 * @param string $id The ID of the module.
37 * @param string $type The type of the module.
38 */
39 public function __construct($id, $type) {
40 Util::logInitClass($this);
41 $this->reload($id, $type);
42 }
43
44 /**
45 * Reloads the module configuration based on the provided ID and type.
46 *
47 * @param string|null $id The ID of the module. If null, the current ID is used.
48 * @param string|null $type The type of the module. If null, the current type is used.
49 */
50 public function reload($id = null, $type = null) {
53
54 $this->name = $bearsamppLang->getValue(Lang::PHPPGADMIN);
55 $this->version = $bearsamppConfig->getRaw(self::ROOT_CFG_VERSION);
56 parent::reload($id, $type);
57
58 if ($this->bearsamppConfRaw !== false) {
59 $this->conf = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CONF];
60 }
61
62 if (!$this->enable) {
63 Util::logInfo($this->name . ' is not enabled!');
64 return;
65 }
66 if (!is_dir($this->currentPath)) {
67 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->currentPath));
68 }
69 if (!is_dir($this->symlinkPath)) {
70 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->symlinkPath));
71 return;
72 }
73 if (!is_file($this->bearsamppConf)) {
74 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->bearsamppConf));
75 }
76 if (!is_file($this->conf)) {
77 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->conf));
78 }
79 }
80
81 /**
82 * Updates the module configuration with a specific version.
83 *
84 * @param string|null $version The version to update to. If null, the current version is used.
85 * @param int $sub The sub-level for logging indentation.
86 * @param bool $showWindow Whether to show a window during the update process.
87 * @return bool True if the update was successful, false otherwise.
88 */
89 protected function updateConfig($version = null, $sub = 0, $showWindow = false) {
91
92 if (!$this->enable) {
93 return true;
94 }
95
96 $version = $version == null ? $this->version : $version;
97 Util::logDebug(($sub > 0 ? str_repeat(' ', 2 * $sub) : '') . 'Update ' . $this->name . ' ' . $version . ' config');
98
99 $alias = $bearsamppRoot->getAliasPath() . '/phppgadmin.conf';
100 if (is_file($alias)) {
101 Util::replaceInFile($alias, array(
102 '/^Alias\s\/phppgadmin\s.*/' => 'Alias /phppgadmin "' . $this->getSymlinkPath() . '/"',
103 '/^<Directory\s.*/' => '<Directory "' . $this->getSymlinkPath() . '/">',
104 ));
105 } else {
106 Util::logError($this->getName() . ' alias not found : ' . $alias);
107 }
108
109 if ($bearsamppBins->getPostgresql()->isEnable()) {
110 Util::replaceInFile($this->getConf(), array(
111 '/^\$postgresqlPort\s=\s(\d+)/' => '$postgresqlPort = ' . $bearsamppBins->getPostgresql()->getPort() . ';',
112 '/^\$postgresqlRootUser\s=\s/' => '$postgresqlRootUser = \'' . $bearsamppBins->getPostgresql()->getRootUser() . '\';',
113 '/^\$postgresqlRootPwd\s=\s/' => '$postgresqlRootPwd = \'' . $bearsamppBins->getPostgresql()->getRootPwd() . '\';',
114 '/^\$postgresqlDumpExe\s=\s/' => '$postgresqlDumpExe = \'' . $bearsamppBins->getPostgresql()->getDumpExe() . '\';',
115 '/^\$postgresqlDumpAllExe\s=\s/' => '$postgresqlDumpAllExe = \'' . $bearsamppBins->getPostgresql()->getDumpAllExe() . '\';',
116 ));
117 }
118
119 return true;
120 }
121
122 /**
123 * Sets the version of the module.
124 *
125 * @param string $version The version to set.
126 */
127 public function setVersion($version) {
128 global $bearsamppConfig;
129 $this->version = $version;
130 $bearsamppConfig->replace(self::ROOT_CFG_VERSION, $version);
131 $this->reload();
132 }
133
134 /**
135 * Gets the path to the phpPgAdmin configuration file.
136 *
137 * @return string The path to the configuration file.
138 */
139 public function getConf() {
140 return $this->conf;
141 }
142}
global $bearsamppBins
global $bearsamppLang
global $bearsamppRoot
reload($id=null, $type=null)
updateConfig($version=null, $sub=0, $showWindow=false)
const ERROR_FILE_NOT_FOUND
const PHPPGADMIN
const ERROR_CONF_NOT_FOUND
static logReloadClass($classInstance)
static replaceInFile($path, $replaceList)
static logError($data, $file=null)
static logDebug($data, $file=null)
static logInitClass($classInstance)
static logInfo($data, $file=null)
global $bearsamppConfig
Definition homepage.php:26