Bearsampp 2025.8.29
Loading...
Searching...
No Matches
class.tpl.app.mariadb.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
11{
12 const MENU = 'mariadb';
13 const MENU_VERSIONS = 'mariadbVersions';
14 const MENU_SERVICE = 'mariadbService';
15 const MENU_DEBUG = 'mariadbDebug';
16
17 const ACTION_ENABLE = 'enableMariadb';
18 const ACTION_SWITCH_VERSION = 'switchMariadbVersion';
19 const ACTION_CHANGE_PORT = 'changeMariadbPort';
20 const ACTION_CHANGE_ROOT_PWD = 'changeMariadbRootPwd';
21 const ACTION_INSTALL_SERVICE = 'installMariadbService';
22 const ACTION_REMOVE_SERVICE = 'removeMariadbService';
23
35 public static function process()
36 {
38
39 return TplApp::getMenuEnable($bearsamppLang->getValue(Lang::MARIADB), self::MENU, get_called_class(), $bearsamppBins->getMariadb()->isEnable());
40 }
41
55 public static function getMenuMariadb()
56 {
57 global $bearsamppBins, $bearsamppLang, $bearsamppTools;
58 $resultItems = $resultActions = '';
59
60 $isEnabled = $bearsamppBins->getMariadb()->isEnable();
61
62 // Download
64 Util::getWebsiteUrl('module/mariadb', '#releases'),
65 false,
67 ) . PHP_EOL;
68
69 // Enable
70 $tplEnable = TplApp::getActionMulti(
71 self::ACTION_ENABLE, array($isEnabled ? Config::DISABLED : Config::ENABLED),
72 array($bearsamppLang->getValue(Lang::MENU_ENABLE), $isEnabled ? TplAestan::GLYPH_CHECK : ''),
73 false, get_called_class()
74 );
75 $resultItems .= $tplEnable[TplApp::SECTION_CALL] . PHP_EOL;
76 $resultActions .= $tplEnable[TplApp::SECTION_CONTENT] . PHP_EOL;
77
78 if ($isEnabled) {
79 $resultItems .= TplAestan::getItemSeparator() . PHP_EOL;
80
81 // Versions
82 $tplVersions = TplApp::getMenu($bearsamppLang->getValue(Lang::VERSIONS), self::MENU_VERSIONS, get_called_class());
83 $resultItems .= $tplVersions[TplApp::SECTION_CALL] . PHP_EOL;
84 $resultActions .= $tplVersions[TplApp::SECTION_CONTENT] . PHP_EOL;
85
86 // Service
87 $tplService = TplApp::getMenu($bearsamppLang->getValue(Lang::SERVICE), self::MENU_SERVICE, get_called_class());
88 $resultItems .= $tplService[TplApp::SECTION_CALL] . PHP_EOL;
89 $resultActions .= $tplService[TplApp::SECTION_CONTENT] . PHP_EOL;
90
91 // Debug
92 $tplDebug = TplApp::getMenu($bearsamppLang->getValue(Lang::DEBUG), self::MENU_DEBUG, get_called_class());
93 $resultItems .= $tplDebug[TplApp::SECTION_CALL] . PHP_EOL;
94 $resultActions .= $tplDebug[TplApp::SECTION_CONTENT];
95
96 // Console
97 $resultItems .= TplAestan::getItemConsoleZ(
100 $bearsamppTools->getConsoleZ()->getTabTitleMariadb()
101 ) . PHP_EOL;
102
103 // Conf
104 $resultItems .= TplAestan::getItemNotepad(basename($bearsamppBins->getMariadb()->getConf()), $bearsamppBins->getMariadb()->getConf()) . PHP_EOL;
105
106 // Errors log
107 $resultItems .= TplAestan::getItemNotepad($bearsamppLang->getValue(Lang::MENU_ERROR_LOGS), $bearsamppBins->getMariadb()->getErrorLog()) . PHP_EOL;
108 }
109
110 return $resultItems . PHP_EOL . $resultActions;
111 }
112
123 public static function getMenuMariadbVersions()
124 {
125 global $bearsamppBins;
126 $items = '';
127 $actions = '';
128
129 foreach ($bearsamppBins->getMariadb()->getVersionList() as $version) {
130 $tplSwitchMariadbVersion = TplApp::getActionMulti(
131 self::ACTION_SWITCH_VERSION, array($version),
132 array($version, $version == $bearsamppBins->getMariadb()->getVersion() ? TplAestan::GLYPH_CHECK : ''),
133 false, get_called_class()
134 );
135
136 // Item
137 $items .= $tplSwitchMariadbVersion[TplApp::SECTION_CALL] . PHP_EOL;
138
139 // Action
140 $actions .= PHP_EOL . $tplSwitchMariadbVersion[TplApp::SECTION_CONTENT];
141 }
142
143 return $items . $actions;
144 }
145
158 public static function getActionEnableMariadb($enable)
159 {
160 global $bearsamppBins;
161
162 return TplApp::getActionRun(Action::ENABLE, array($bearsamppBins->getMariadb()->getName(), $enable)) . PHP_EOL .
164 }
165
178 public static function getActionSwitchMariadbVersion($version)
179 {
180 global $bearsamppBins;
181
182 return TplApp::getActionRun(Action::SWITCH_VERSION, array($bearsamppBins->getMariadb()->getName(), $version)) . PHP_EOL .
184 }
185
198 public static function getMenuMariadbService()
199 {
201
202 $tplChangePort = TplApp::getActionMulti(
203 self::ACTION_CHANGE_PORT, null,
205 false, get_called_class()
206 );
207
208 $isInstalled = $bearsamppBins->getMariadb()->getService()->isInstalled();
209
210 $result = TplAestan::getItemActionServiceStart($bearsamppBins->getMariadb()->getService()->getName()) . PHP_EOL .
211 TplAestan::getItemActionServiceStop($bearsamppBins->getMariadb()->getService()->getName()) . PHP_EOL .
212 TplAestan::getItemActionServiceRestart($bearsamppBins->getMariadb()->getService()->getName()) . PHP_EOL .
213 TplAestan::getItemSeparator() . PHP_EOL .
215 Action::CHECK_PORT, array($bearsamppBins->getMariadb()->getName(), $bearsamppBins->getMariadb()->getPort()),
216 array(sprintf($bearsamppLang->getValue(Lang::MENU_CHECK_PORT), $bearsamppBins->getMariadb()->getPort()), TplAestan::GLYPH_LIGHT)
217 ) . PHP_EOL .
218 $tplChangePort[TplApp::SECTION_CALL] . PHP_EOL;
219
220 $tplChangeRootPwd = null;
221 if ($isInstalled) {
222 $tplChangeRootPwd = TplApp::getActionMulti(
223 self::ACTION_CHANGE_ROOT_PWD, null,
225 !$isInstalled, 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, null,
235 $isInstalled, get_called_class()
236 );
237
238 $result .= $tplInstallService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
239 $tplInstallService[TplApp::SECTION_CONTENT] . PHP_EOL;
240 } else {
241 $tplRemoveService = TplApp::getActionMulti(
242 self::ACTION_REMOVE_SERVICE, null,
244 !$isInstalled, get_called_class()
245 );
246
247 $result .= $tplRemoveService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
248 $tplRemoveService[TplApp::SECTION_CONTENT] . PHP_EOL;
249 }
250
251 $result .= $tplChangePort[TplApp::SECTION_CONTENT] . PHP_EOL .
252 ($tplChangeRootPwd != null ? $tplChangeRootPwd[TplApp::SECTION_CONTENT] . PHP_EOL : '');
253
254 return $result;
255 }
256
284
295 public static function getActionChangeMariadbPort()
296 {
297 global $bearsamppBins;
298
299 return TplApp::getActionRun(Action::CHANGE_PORT, array($bearsamppBins->getMariadb()->getName())) . PHP_EOL .
301 }
302
313 public static function getActionChangeMariadbRootPwd()
314 {
315 global $bearsamppBins;
316
317 return TplApp::getActionRun(Action::CHANGE_DB_ROOT_PWD, array($bearsamppBins->getMariadb()->getName())) . PHP_EOL .
319 }
320
333
346}
$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
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
const GLYPH_SERVICE_REMOVE
static getItemActionServiceStop($service)
static getItemConsoleZ($caption, $glyph, $id=null, $title=null, $initDir=null, $command=null)
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()
static getWebsiteUrl($path='', $fragment='', $utmSource=true)