Bearsampp 2026.9.23
Loading...
Searching...
No Matches
class.tpl.app.postgresql.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2026 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
18{
19 const MENU = 'postgresql';
20 const MENU_VERSIONS = 'postgresqlVersions';
21 const MENU_SERVICE = 'postgresqlService';
22 const MENU_DEBUG = 'postgresqlDebug';
23
24 const ACTION_ENABLE = 'enablePostgresql';
25 const ACTION_SWITCH_VERSION = 'switchPostgresqlVersion';
26 const ACTION_CHANGE_PORT = 'changePostgresqlPort';
27 const ACTION_CHANGE_ROOT_PWD = 'changePostgresqlRootPwd';
28 const ACTION_INSTALL_SERVICE = 'installPostgresqlService';
29 const ACTION_REMOVE_SERVICE = 'removePostgresqlService';
30
39 public static function process()
40 {
42
43 return TplApp::getMenuEnable($bearsamppLang->getValue(Lang::POSTGRESQL), self::MENU, get_called_class(), $bearsamppBins->getPostgresql()->isEnable());
44 }
45
55 public static function getMenuPostgresql()
56 {
57 global $bearsamppBins, $bearsamppLang, $bearsamppTools;
58 $resultItems = $resultActions = '';
59
60 $isEnabled = $bearsamppBins->getPostgresql()->isEnable();
61
62 // Download
63 $resultItems .= TplAestan::getItemLink(
65 HttpClient::getWebsiteUrl('module/postgresql', '#releases'),
66 false,
68 ) . PHP_EOL;
69
70 // Enable
71 $tplEnable = TplApp::getActionMulti(
72 self::ACTION_ENABLE,
73 array($isEnabled ? Config::DISABLED : Config::ENABLED),
74 array($bearsamppLang->getValue(Lang::MENU_ENABLE), $isEnabled ? TplAestan::GLYPH_CHECK : ''),
75 false,
76 get_called_class()
77 );
78 $resultItems .= $tplEnable[TplApp::SECTION_CALL] . PHP_EOL;
79 $resultActions .= $tplEnable[TplApp::SECTION_CONTENT] . PHP_EOL;
80
81 if ($isEnabled) {
82 $resultItems .= TplAestan::getItemSeparator() . PHP_EOL;
83
84 // Versions
85 $tplVersions = TplApp::getMenu($bearsamppLang->getValue(Lang::VERSIONS), self::MENU_VERSIONS, get_called_class());
86 $resultItems .= $tplVersions[TplApp::SECTION_CALL] . PHP_EOL;
87 $resultActions .= $tplVersions[TplApp::SECTION_CONTENT] . PHP_EOL;
88
89 // Service
90 $tplService = TplApp::getMenu($bearsamppLang->getValue(Lang::SERVICE), self::MENU_SERVICE, get_called_class());
91 $resultItems .= $tplService[TplApp::SECTION_CALL] . PHP_EOL;
92 $resultActions .= $tplService[TplApp::SECTION_CONTENT] . PHP_EOL;
93
94 // Debug
95 $tplDebug = TplApp::getMenu($bearsamppLang->getValue(Lang::DEBUG), self::MENU_DEBUG, get_called_class());
96 $resultItems .= $tplDebug[TplApp::SECTION_CALL] . PHP_EOL;
97 $resultActions .= $tplDebug[TplApp::SECTION_CONTENT];
98
99 // Console
100 $resultItems .= TplAestan::getItemPowerShell(
101 $bearsamppLang->getValue(Lang::CONSOLE),
103 null,
104 $bearsamppTools->getPowerShell()->getTabTitlePostgresql(),
106 null
107 ) . PHP_EOL;
108
109 // Conf
110 $resultItems .= TplAestan::getItemNotepad(basename($bearsamppBins->getPostgresql()->getConf()), $bearsamppBins->getPostgresql()->getConf()) . PHP_EOL;
111
112 // Errors log
113 $resultItems .= TplAestan::getItemNotepad($bearsamppLang->getValue(Lang::MENU_ERROR_LOGS), $bearsamppBins->getPostgresql()->getErrorLog()) . PHP_EOL;
114 }
115
116 return $resultItems . PHP_EOL . $resultActions;
117 }
118
126 public static function getMenuPostgresqlVersions()
127 {
128 global $bearsamppBins;
129 $items = '';
130 $actions = '';
131
132 foreach ($bearsamppBins->getPostgresql()->getVersionList() as $version) {
133 $tplSwitchPostgresqlVersion = TplApp::getActionMulti(
134 self::ACTION_SWITCH_VERSION,
135 array($version),
136 array($version, $version == $bearsamppBins->getPostgresql()->getVersion() ? TplAestan::GLYPH_CHECK : ''),
137 false,
138 get_called_class()
139 );
140
141 // Item
142 $items .= $tplSwitchPostgresqlVersion[TplApp::SECTION_CALL] . PHP_EOL;
143
144 // Action
145 $actions .= PHP_EOL . $tplSwitchPostgresqlVersion[TplApp::SECTION_CONTENT];
146 }
147
148 return $items . $actions;
149 }
150
160 public static function getActionEnablePostgresql($enable)
161 {
162 global $bearsamppBins;
163
164 return TplApp::getActionRun(Action::ENABLE, array($bearsamppBins->getPostgresql()->getName(), $enable)) . PHP_EOL .
166 }
167
177 public static function getActionSwitchPostgresqlVersion($version)
178 {
179 global $bearsamppBins;
180
181 return TplApp::getActionRun(Action::SWITCH_VERSION, array($bearsamppBins->getPostgresql()->getName(), $version)) . PHP_EOL .
183 }
184
193 public static function getMenuPostgresqlService()
194 {
196
197 $tplChangePort = TplApp::getActionMulti(
198 self::ACTION_CHANGE_PORT,
199 null,
201 false,
202 get_called_class()
203 );
204
205 $isInstalled = $bearsamppBins->getPostgresql()->getService()->isInstalled();
206
207 $result = TplAestan::getItemActionServiceStart($bearsamppBins->getPostgresql()->getService()->getName()) . PHP_EOL .
208 TplAestan::getItemActionServiceStop($bearsamppBins->getPostgresql()->getService()->getName()) . PHP_EOL .
209 TplAestan::getItemActionServiceRestart($bearsamppBins->getPostgresql()->getService()->getName()) . PHP_EOL .
210 TplAestan::getItemSeparator() . PHP_EOL .
213 array($bearsamppBins->getPostgresql()->getName(), $bearsamppBins->getPostgresql()->getPort()),
214 array(sprintf($bearsamppLang->getValue(Lang::MENU_CHECK_PORT), $bearsamppBins->getPostgresql()->getPort()), TplAestan::GLYPH_LIGHT)
215 ) . PHP_EOL .
216 $tplChangePort[TplApp::SECTION_CALL] . PHP_EOL;
217
218 $tplChangeRootPwd = null;
219 if ($isInstalled) {
220 $tplChangeRootPwd = TplApp::getActionMulti(
221 self::ACTION_CHANGE_ROOT_PWD,
222 null,
224 !$isInstalled,
225 get_called_class()
226 );
227
228 $result .= $tplChangeRootPwd[TplApp::SECTION_CALL] . PHP_EOL;
229 }
230
231 if (!$isInstalled) {
232 $tplInstallService = TplApp::getActionMulti(
233 self::ACTION_INSTALL_SERVICE,
234 null,
236 $isInstalled,
237 get_called_class()
238 );
239
240 $result .= $tplInstallService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
241 $tplInstallService[TplApp::SECTION_CONTENT] . PHP_EOL;
242 } else {
243 $tplRemoveService = TplApp::getActionMulti(
244 self::ACTION_REMOVE_SERVICE,
245 null,
247 !$isInstalled,
248 get_called_class()
249 );
250
251 $result .= $tplRemoveService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
252 $tplRemoveService[TplApp::SECTION_CONTENT] . PHP_EOL;
253 }
254
255 $result .= $tplChangePort[TplApp::SECTION_CONTENT] . PHP_EOL .
256 ($tplChangeRootPwd != null ? $tplChangeRootPwd[TplApp::SECTION_CONTENT] . PHP_EOL : '');
257
258 return $result;
259 }
260
268 public static function getMenuPostgresqlDebug()
269 {
270 global $bearsamppLang;
271
276 ) . PHP_EOL;
277 }
278
286 public static function getActionChangePostgresqlPort()
287 {
288 global $bearsamppBins;
289
290 return TplApp::getActionRun(Action::CHANGE_PORT, array($bearsamppBins->getPostgresql()->getName())) . PHP_EOL .
292 }
293
301 public static function getActionChangePostgresqlRootPwd()
302 {
303 global $bearsamppBins;
304
305 return TplApp::getActionRun(Action::CHANGE_DB_ROOT_PWD, array($bearsamppBins->getPostgresql()->getName())) . PHP_EOL .
307 }
308
319
330}
$result
global $bearsamppBins
global $bearsamppLang
const SWITCH_VERSION
const CHANGE_DB_ROOT_PWD
const SERVICE
const CHANGE_PORT
const DEBUG_POSTGRESQL
const CHECK_PORT
const ENABLE
const DISABLED
const ENABLED
static getWebsiteUrl($path='', $fragment='', $utmSource=true)
const MENU_ENABLE
const MENU_CHANGE_ROOT_PWD
const DEBUG_POSTGRESQL_VERSION
const SERVICE
const DOWNLOAD_MORE
const CONSOLE
const MENU_CHANGE_PORT
const POSTGRESQL
const DEBUG
const MENU_ERROR_LOGS
const MENU_INSTALL_SERVICE
const MENU_REMOVE_SERVICE
const MENU_CHECK_PORT
const VERSIONS
static getModuleSymlinkPath($module)
static getItemPowerShell($caption, $glyph, $id=null, $title=null, $initDir=null, $command=null)
const GLYPH_POWERSHELL
const GLYPH_SERVICE_REMOVE
static getItemActionServiceStop($service)
const GLYPH_SERVICE_INSTALL
static getItemLink($caption, $link, $local=false, $glyph=self::GLYPH_WEB_PAGE)
static getItemNotepad($caption, $path)
static getItemActionServiceStart($service)
static getItemSeparator()
static getItemActionServiceRestart($service)
static getActionMulti($action, $args=array(), $item=array(), $disabled=false, $class=false)
static getMenu($caption, $menu, $class)
static getActionRun($action, $args=array(), $item=array(), $waitUntilTerminated=true)
const SECTION_CALL
const SECTION_CONTENT
static getMenuEnable($caption, $menu, $class, $enabled=true)
static getActionEnablePostgresql($enable)
static getActionSwitchPostgresqlVersion($version)