Bearsampp 2026.9.23
Loading...
Searching...
No Matches
class.tpl.app.mariadb.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 = 'mariadb';
20 const MENU_VERSIONS = 'mariadbVersions';
21 const MENU_SERVICE = 'mariadbService';
22 const MENU_DEBUG = 'mariadbDebug';
23
24 const ACTION_ENABLE = 'enableMariadb';
25 const ACTION_SWITCH_VERSION = 'switchMariadbVersion';
26 const ACTION_CHANGE_PORT = 'changeMariadbPort';
27 const ACTION_CHANGE_ROOT_PWD = 'changeMariadbRootPwd';
28 const ACTION_INSTALL_SERVICE = 'installMariadbService';
29 const ACTION_REMOVE_SERVICE = 'removeMariadbService';
30
42 public static function process()
43 {
45
46 return TplApp::getMenuEnable($bearsamppLang->getValue(Lang::MARIADB), self::MENU, get_called_class(), $bearsamppBins->getMariadb()->isEnable());
47 }
48
62 public static function getMenuMariadb()
63 {
64 global $bearsamppBins, $bearsamppLang, $bearsamppTools;
65 $resultItems = $resultActions = '';
66
67 $isEnabled = $bearsamppBins->getMariadb()->isEnable();
68
69 // Download
70 $resultItems .= TplAestan::getItemLink(
72 HttpClient::getWebsiteUrl('module/mariadb', '#releases'),
73 false,
75 ) . PHP_EOL;
76
77 // Enable
78 $tplEnable = TplApp::getActionMulti(
79 self::ACTION_ENABLE,
80 array($isEnabled ? Config::DISABLED : Config::ENABLED),
81 array($bearsamppLang->getValue(Lang::MENU_ENABLE), $isEnabled ? TplAestan::GLYPH_CHECK : ''),
82 false,
83 get_called_class()
84 );
85 $resultItems .= $tplEnable[TplApp::SECTION_CALL] . PHP_EOL;
86 $resultActions .= $tplEnable[TplApp::SECTION_CONTENT] . PHP_EOL;
87
88 if ($isEnabled) {
89 $resultItems .= TplAestan::getItemSeparator() . PHP_EOL;
90
91 // Versions
92 $tplVersions = TplApp::getMenu($bearsamppLang->getValue(Lang::VERSIONS), self::MENU_VERSIONS, get_called_class());
93 $resultItems .= $tplVersions[TplApp::SECTION_CALL] . PHP_EOL;
94 $resultActions .= $tplVersions[TplApp::SECTION_CONTENT] . PHP_EOL;
95
96 // Service
97 $tplService = TplApp::getMenu($bearsamppLang->getValue(Lang::SERVICE), self::MENU_SERVICE, get_called_class());
98 $resultItems .= $tplService[TplApp::SECTION_CALL] . PHP_EOL;
99 $resultActions .= $tplService[TplApp::SECTION_CONTENT] . PHP_EOL;
100
101 // Debug
102 $tplDebug = TplApp::getMenu($bearsamppLang->getValue(Lang::DEBUG), self::MENU_DEBUG, get_called_class());
103 $resultItems .= $tplDebug[TplApp::SECTION_CALL] . PHP_EOL;
104 $resultActions .= $tplDebug[TplApp::SECTION_CONTENT];
105
106 // Console
107 $resultItems .= TplAestan::getItemPowerShell(
108 $bearsamppLang->getValue(Lang::CONSOLE),
110 null,
111 $bearsamppTools->getPowerShell()->getTabTitleMariadb(),
113 null
114 ) . PHP_EOL;
115
116 // Conf
117 $resultItems .= TplAestan::getItemNotepad(basename($bearsamppBins->getMariadb()->getConf()), $bearsamppBins->getMariadb()->getConf()) . PHP_EOL;
118
119 // Errors log
120 $resultItems .= TplAestan::getItemNotepad($bearsamppLang->getValue(Lang::MENU_ERROR_LOGS), $bearsamppBins->getMariadb()->getErrorLog()) . PHP_EOL;
121 }
122
123 return $resultItems . PHP_EOL . $resultActions;
124 }
125
136 public static function getMenuMariadbVersions()
137 {
138 global $bearsamppBins;
139 $items = '';
140 $actions = '';
141
142 foreach ($bearsamppBins->getMariadb()->getVersionList() as $version) {
143 $tplSwitchMariadbVersion = TplApp::getActionMulti(
144 self::ACTION_SWITCH_VERSION,
145 array($version),
146 array($version, $version == $bearsamppBins->getMariadb()->getVersion() ? TplAestan::GLYPH_CHECK : ''),
147 false,
148 get_called_class()
149 );
150
151 // Item
152 $items .= $tplSwitchMariadbVersion[TplApp::SECTION_CALL] . PHP_EOL;
153
154 // Action
155 $actions .= PHP_EOL . $tplSwitchMariadbVersion[TplApp::SECTION_CONTENT];
156 }
157
158 return $items . $actions;
159 }
160
173 public static function getActionEnableMariadb($enable)
174 {
175 global $bearsamppBins;
176
177 return TplApp::getActionRun(Action::ENABLE, array($bearsamppBins->getMariadb()->getName(), $enable)) . PHP_EOL .
179 }
180
193 public static function getActionSwitchMariadbVersion($version)
194 {
195 global $bearsamppBins;
196
197 return TplApp::getActionRun(Action::SWITCH_VERSION, array($bearsamppBins->getMariadb()->getName(), $version)) . PHP_EOL .
199 }
200
213 public static function getMenuMariadbService()
214 {
216
217 $tplChangePort = TplApp::getActionMulti(
218 self::ACTION_CHANGE_PORT,
219 null,
221 false,
222 get_called_class()
223 );
224
225 $isInstalled = $bearsamppBins->getMariadb()->getService()->isInstalled();
226
227 $result = TplAestan::getItemActionServiceStart($bearsamppBins->getMariadb()->getService()->getName()) . PHP_EOL .
228 TplAestan::getItemActionServiceStop($bearsamppBins->getMariadb()->getService()->getName()) . PHP_EOL .
229 TplAestan::getItemActionServiceRestart($bearsamppBins->getMariadb()->getService()->getName()) . PHP_EOL .
230 TplAestan::getItemSeparator() . PHP_EOL .
233 array($bearsamppBins->getMariadb()->getName(), $bearsamppBins->getMariadb()->getPort()),
234 array(sprintf($bearsamppLang->getValue(Lang::MENU_CHECK_PORT), $bearsamppBins->getMariadb()->getPort()), TplAestan::GLYPH_LIGHT)
235 ) . PHP_EOL .
236 $tplChangePort[TplApp::SECTION_CALL] . PHP_EOL;
237
238 $tplChangeRootPwd = null;
239 if ($isInstalled) {
240 $tplChangeRootPwd = TplApp::getActionMulti(
241 self::ACTION_CHANGE_ROOT_PWD,
242 null,
244 !$isInstalled,
245 get_called_class()
246 );
247
248 $result .= $tplChangeRootPwd[TplApp::SECTION_CALL] . PHP_EOL;
249 }
250
251 if (!$isInstalled) {
252 $tplInstallService = TplApp::getActionMulti(
253 self::ACTION_INSTALL_SERVICE,
254 null,
256 $isInstalled,
257 get_called_class()
258 );
259
260 $result .= $tplInstallService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
261 $tplInstallService[TplApp::SECTION_CONTENT] . PHP_EOL;
262 } else {
263 $tplRemoveService = TplApp::getActionMulti(
264 self::ACTION_REMOVE_SERVICE,
265 null,
267 !$isInstalled,
268 get_called_class()
269 );
270
271 $result .= $tplRemoveService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
272 $tplRemoveService[TplApp::SECTION_CONTENT] . PHP_EOL;
273 }
274
275 $result .= $tplChangePort[TplApp::SECTION_CONTENT] . PHP_EOL .
276 ($tplChangeRootPwd != null ? $tplChangeRootPwd[TplApp::SECTION_CONTENT] . PHP_EOL : '');
277
278 return $result;
279 }
280
311
322 public static function getActionChangeMariadbPort()
323 {
324 global $bearsamppBins;
325
326 return TplApp::getActionRun(Action::CHANGE_PORT, array($bearsamppBins->getMariadb()->getName())) . PHP_EOL .
328 }
329
340 public static function getActionChangeMariadbRootPwd()
341 {
342 global $bearsamppBins;
343
344 return TplApp::getActionRun(Action::CHANGE_DB_ROOT_PWD, array($bearsamppBins->getMariadb()->getName())) . PHP_EOL .
346 }
347
360
373}
$result
global $bearsamppBins
global $bearsamppLang
const SWITCH_VERSION
const DEBUG_MARIADB
const CHANGE_DB_ROOT_PWD
const SERVICE
const CHANGE_PORT
const CHECK_PORT
const ENABLE
const DISABLED
const ENABLED
static getWebsiteUrl($path='', $fragment='', $utmSource=true)
const MARIADB
const MENU_ENABLE
const DEBUG_MARIADB_VARIABLES
const MENU_CHANGE_ROOT_PWD
const SERVICE
const DOWNLOAD_MORE
const DEBUG_MARIADB_SYNTAX_CHECK
const CONSOLE
const MENU_CHANGE_PORT
const DEBUG
const MENU_ERROR_LOGS
const MENU_INSTALL_SERVICE
const DEBUG_MARIADB_VERSION
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 getActionChangeMariadbPort()
static getActionInstallMariadbService()
static getActionSwitchMariadbVersion($version)
static getActionEnableMariadb($enable)
static getActionRemoveMariadbService()
static getActionChangeMariadbRootPwd()