2024.8.23
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
24 /**
25 * Processes the MariaDB menu.
26 *
27 * This method generates the MariaDB menu and determines if MariaDB is enabled.
28 * It uses the global language and binaries objects to retrieve the necessary values.
29 *
30 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
31 * @global object $bearsamppBins Provides access to system binaries and their configurations.
32 *
33 * @return array The generated MariaDB menu.
34 */
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
42 /**
43 * Generates the MariaDB menu items and actions.
44 *
45 * This method creates menu items and actions for managing MariaDB, including enabling/disabling,
46 * switching versions, managing services, and debugging. It uses the global language, binaries,
47 * and tools objects to retrieve the necessary values.
48 *
49 * @global object $bearsamppBins Provides access to system binaries and their configurations.
50 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
51 * @global object $bearsamppTools Provides access to various tools and utilities.
52 *
53 * @return string The generated MariaDB menu items and actions.
54 */
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
113 /**
114 * Generates the MariaDB versions menu items and actions.
115 *
116 * This method creates menu items and actions for switching between different MariaDB versions.
117 * It uses the global binaries object to retrieve the available versions.
118 *
119 * @global object $bearsamppBins Provides access to system binaries and their configurations.
120 *
121 * @return string The generated MariaDB versions menu items and actions.
122 */
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
146 /**
147 * Generates the action to enable or disable MariaDB.
148 *
149 * This method creates the action string for enabling or disabling MariaDB.
150 * It uses the global binaries object to retrieve the necessary values.
151 *
152 * @global object $bearsamppBins Provides access to system binaries and their configurations.
153 *
154 * @param int $enable The enable flag (1 for enable, 0 for disable).
155 *
156 * @return string The generated action string for enabling or disabling MariaDB.
157 */
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
166 /**
167 * Generates the action to switch the MariaDB version.
168 *
169 * This method creates the action string for switching the MariaDB version.
170 * It uses the global binaries object to retrieve the necessary values.
171 *
172 * @global object $bearsamppBins Provides access to system binaries and their configurations.
173 *
174 * @param string $version The version to switch to.
175 *
176 * @return string The generated action string for switching the MariaDB version.
177 */
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
186 /**
187 * Generates the MariaDB service menu items and actions.
188 *
189 * This method creates menu items and actions for managing the MariaDB service, including starting,
190 * stopping, restarting, changing the port, and changing the root password. It uses the global language
191 * and binaries objects to retrieve the necessary values.
192 *
193 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
194 * @global object $bearsamppBins Provides access to system binaries and their configurations.
195 *
196 * @return string The generated MariaDB service menu items and actions.
197 */
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
257 /**
258 * Generates the MariaDB debug menu items and actions.
259 *
260 * This method creates menu items and actions for debugging MariaDB, including checking the version,
261 * variables, and syntax. It uses the global language object to retrieve the necessary values.
262 *
263 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
264 *
265 * @return string The generated MariaDB debug menu items and actions.
266 */
284
285 /**
286 * Generates the action to change the MariaDB port.
287 *
288 * This method creates the action string for changing the MariaDB port.
289 * It uses the global binaries object to retrieve the necessary values.
290 *
291 * @global object $bearsamppBins Provides access to system binaries and their configurations.
292 *
293 * @return string The generated action string for changing the MariaDB port.
294 */
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
303 /**
304 * Generates the action to change the MariaDB root password.
305 *
306 * This method creates the action string for changing the MariaDB root password.
307 * It uses the global binaries object to retrieve the necessary values.
308 *
309 * @global object $bearsamppBins Provides access to system binaries and their configurations.
310 *
311 * @return string The generated action string for changing the MariaDB root password.
312 */
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
321 /**
322 * Generates the action to install the MariaDB service.
323 *
324 * This method creates the action string for installing the MariaDB service.
325 *
326 * @return string The generated action string for installing the MariaDB service.
327 */
333
334 /**
335 * Generates the action to remove the MariaDB service.
336 *
337 * This method creates the action string for removing the MariaDB service.
338 *
339 * @return string The generated action string for removing the MariaDB service.
340 */
346}
$result
global $bearsamppBins
global $bearsamppLang
const DEBUG_MARIADB
const CHANGE_PORT
const CHECK_PORT
const ENABLE
const SWITCH_VERSION
const SERVICE
const CHANGE_DB_ROOT_PWD
const DISABLED
const ENABLED
const MENU_ERROR_LOGS
const VERSIONS
const DEBUG_MARIADB_SYNTAX_CHECK
const MENU_INSTALL_SERVICE
const MARIADB
const DEBUG_MARIADB_VERSION
const MENU_CHANGE_ROOT_PWD
const DEBUG
const MENU_ENABLE
const DOWNLOAD_MORE
const MENU_REMOVE_SERVICE
const CONSOLE
const DEBUG_MARIADB_VARIABLES
const MENU_CHECK_PORT
const SERVICE
const MENU_CHANGE_PORT
const GLYPH_SERVICE_REMOVE
static getItemActionServiceStop($service)
static getItemSeparator()
static getItemActionServiceStart($service)
static getItemConsoleZ($caption, $glyph, $id=null, $title=null, $initDir=null, $command=null)
static getItemActionServiceRestart($service)
static getItemLink($caption, $link, $local=false, $glyph=self::GLYPH_WEB_PAGE)
const GLYPH_SERVICE_INSTALL
static getItemNotepad($caption, $path)
static getActionEnableMariadb($enable)
static getActionInstallMariadbService()
static getActionChangeMariadbRootPwd()
static getActionSwitchMariadbVersion($version)
static getActionRemoveMariadbService()
static getActionChangeMariadbPort()
static getActionMulti($action, $args=array(), $item=array(), $disabled=false, $class=false)
const SECTION_CALL
static getMenuEnable($caption, $menu, $class, $enabled=true)
const SECTION_CONTENT
static getActionRun($action, $args=array(), $item=array(), $waitUntilTerminated=true)
static getMenu($caption, $menu, $class)
static getWebsiteUrl($path='', $fragment='', $utmSource=true)