2024.8.23
Loading...
Searching...
No Matches
class.tpl.app.mysql.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 TplAppMysql
12 *
13 * This class provides methods to generate and manage menu items, actions, and sections
14 * related to MySQL within the Bearsampp application. It includes functionalities for
15 * enabling/disabling MySQL, switching versions, changing ports, managing services, and debugging.
16 */
18{
19 // Constants for menu and action identifiers
20 const MENU = 'mysql';
21 const MENU_VERSIONS = 'mysqlVersions';
22 const MENU_SERVICE = 'mysqlService';
23 const MENU_DEBUG = 'mysqlDebug';
24
25 const ACTION_ENABLE = 'enableMysql';
26 const ACTION_SWITCH_VERSION = 'switchMysqlVersion';
27 const ACTION_CHANGE_PORT = 'changeMysqlPort';
28 const ACTION_CHANGE_ROOT_PWD = 'changeMysqlRootPwd';
29 const ACTION_INSTALL_SERVICE = 'installMysqlService';
30 const ACTION_REMOVE_SERVICE = 'removeMysqlService';
31
32 /**
33 * Processes and generates the MySQL menu.
34 *
35 * This method generates the MySQL menu and determines if MySQL is enabled.
36 *
37 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
38 * @global object $bearsamppBins Provides access to system binaries and their configurations.
39 *
40 * @return array The generated MySQL menu.
41 */
42 public static function process()
43 {
45
46 return TplApp::getMenuEnable($bearsamppLang->getValue(Lang::MYSQL), self::MENU, get_called_class(), $bearsamppBins->getMysql()->isEnable());
47 }
48
49 /**
50 * Generates the MySQL menu items and actions.
51 *
52 * This method creates menu items and actions for MySQL, including download links, enabling/disabling,
53 * version switching, service management, debugging, and configuration file access.
54 *
55 * @global object $bearsamppBins Provides access to system binaries and their configurations.
56 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
57 * @global object $bearsamppTools Provides access to various tools used in the application.
58 *
59 * @return string The generated MySQL menu items and actions.
60 */
61 public static function getMenuMysql()
62 {
63 global $bearsamppBins, $bearsamppLang, $bearsamppTools;
64 $resultItems = $resultActions = '';
65
66 $isEnabled = $bearsamppBins->getMysql()->isEnable();
67
68 // Download
70 Util::getWebsiteUrl('module/mysql', '#releases'),
71 false,
73 ) . PHP_EOL;
74
75 // Enable
76 $tplEnable = TplApp::getActionMulti(
77 self::ACTION_ENABLE, array($isEnabled ? Config::DISABLED : Config::ENABLED),
78 array($bearsamppLang->getValue(Lang::MENU_ENABLE), $isEnabled ? TplAestan::GLYPH_CHECK : ''),
79 false, get_called_class()
80 );
81 $resultItems .= $tplEnable[TplApp::SECTION_CALL] . PHP_EOL;
82 $resultActions .= $tplEnable[TplApp::SECTION_CONTENT] . PHP_EOL;
83
84 if ($isEnabled) {
85 $resultItems .= TplAestan::getItemSeparator() . PHP_EOL;
86
87 // Versions
88 $tplVersions = TplApp::getMenu($bearsamppLang->getValue(Lang::VERSIONS), self::MENU_VERSIONS, get_called_class());
89 $resultItems .= $tplVersions[TplApp::SECTION_CALL] . PHP_EOL;
90 $resultActions .= $tplVersions[TplApp::SECTION_CONTENT] . PHP_EOL;
91
92 // Service
93 $tplService = TplApp::getMenu($bearsamppLang->getValue(Lang::SERVICE), self::MENU_SERVICE, get_called_class());
94 $resultItems .= $tplService[TplApp::SECTION_CALL] . PHP_EOL;
95 $resultActions .= $tplService[TplApp::SECTION_CONTENT] . PHP_EOL;
96
97 // Debug
98 $tplDebug = TplApp::getMenu($bearsamppLang->getValue(Lang::DEBUG), self::MENU_DEBUG, get_called_class());
99 $resultItems .= $tplDebug[TplApp::SECTION_CALL] . PHP_EOL;
100 $resultActions .= $tplDebug[TplApp::SECTION_CONTENT];
101
102 // Console
103 $resultItems .= TplAestan::getItemConsoleZ(
104 $bearsamppLang->getValue(Lang::CONSOLE),
106 $bearsamppTools->getConsoleZ()->getTabTitleMysql()
107 ) . PHP_EOL;
108
109 // Conf
110 $resultItems .= TplAestan::getItemNotepad(basename($bearsamppBins->getMysql()->getConf()), $bearsamppBins->getMysql()->getConf()) . PHP_EOL;
111
112 // Errors log
113 $resultItems .= TplAestan::getItemNotepad($bearsamppLang->getValue(Lang::MENU_ERROR_LOGS), $bearsamppBins->getMysql()->getErrorLog()) . PHP_EOL;
114 }
115
116 return $resultItems . PHP_EOL . $resultActions;
117 }
118
119 /**
120 * Generates the MySQL versions menu.
121 *
122 * This method creates menu items and actions for switching between different MySQL versions.
123 *
124 * @global object $bearsamppBins Provides access to system binaries and their configurations.
125 *
126 * @return string The generated MySQL versions menu items and actions.
127 */
128 public static function getMenuMysqlVersions()
129 {
130 global $bearsamppBins;
131 $items = '';
132 $actions = '';
133
134 foreach ($bearsamppBins->getMysql()->getVersionList() as $version) {
135 $tplSwitchMysqlVersion = TplApp::getActionMulti(
136 self::ACTION_SWITCH_VERSION, array($version),
137 array($version, $version == $bearsamppBins->getMysql()->getVersion() ? TplAestan::GLYPH_CHECK : ''),
138 false, get_called_class()
139 );
140
141 // Item
142 $items .= $tplSwitchMysqlVersion[TplApp::SECTION_CALL] . PHP_EOL;
143
144 // Action
145 $actions .= PHP_EOL . $tplSwitchMysqlVersion[TplApp::SECTION_CONTENT];
146 }
147
148 return $items . $actions;
149 }
150
151 /**
152 * Generates the action to enable or disable MySQL.
153 *
154 * This method creates the action string for enabling or disabling MySQL.
155 *
156 * @global object $bearsamppBins Provides access to system binaries and their configurations.
157 *
158 * @param int $enable The enable/disable flag (1 for enable, 0 for disable).
159 * @return string The generated action string for enabling/disabling MySQL.
160 */
161 public static function getActionEnableMysql($enable)
162 {
163 global $bearsamppBins;
164
165 return TplApp::getActionRun(Action::ENABLE, array($bearsamppBins->getMysql()->getName(), $enable)) . PHP_EOL .
167 }
168
169 /**
170 * Generates the action to switch MySQL version.
171 *
172 * This method creates the action string for switching to a different MySQL version.
173 *
174 * @global object $bearsamppBins Provides access to system binaries and their configurations.
175 *
176 * @param string $version The version to switch to.
177 * @return string The generated action string for switching MySQL version.
178 */
179 public static function getActionSwitchMysqlVersion($version)
180 {
181 global $bearsamppBins;
182
183 return TplApp::getActionRun(Action::SWITCH_VERSION, array($bearsamppBins->getMysql()->getName(), $version)) . PHP_EOL .
185 }
186
187 /**
188 * Generates the MySQL service menu.
189 *
190 * This method creates menu items and actions for managing MySQL services, including starting, stopping,
191 * restarting, changing ports, and managing root passwords.
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 MySQL service menu items and actions.
197 */
198 public static function getMenuMysqlService()
199 {
201
202 $tplChangePort = TplApp::getActionMulti(
203 self::ACTION_CHANGE_PORT, null,
205 false, get_called_class()
206 );
207
208 $isInstalled = $bearsamppBins->getMysql()->getService()->isInstalled();
209
210 $result = TplAestan::getItemActionServiceStart($bearsamppBins->getMysql()->getService()->getName()) . PHP_EOL .
211 TplAestan::getItemActionServiceStop($bearsamppBins->getMysql()->getService()->getName()) . PHP_EOL .
212 TplAestan::getItemActionServiceRestart($bearsamppBins->getMysql()->getService()->getName()) . PHP_EOL .
213 TplAestan::getItemSeparator() . PHP_EOL .
215 Action::CHECK_PORT, array($bearsamppBins->getMysql()->getName(), $bearsamppBins->getMysql()->getPort()),
216 array(sprintf($bearsamppLang->getValue(Lang::MENU_CHECK_PORT), $bearsamppBins->getMysql()->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 MySQL debug menu.
259 *
260 * This method creates menu items and actions for debugging MySQL, including checking version,
261 * variables, and syntax.
262 *
263 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
264 *
265 * @return string The generated MySQL debug menu items and actions.
266 */
284
285 /**
286 * Generates the action to change MySQL port.
287 *
288 * This method creates the action string for changing the MySQL port.
289 *
290 * @global object $bearsamppBins Provides access to system binaries and their configurations.
291 *
292 * @return string The generated action string for changing MySQL port.
293 */
294 public static function getActionChangeMysqlPort()
295 {
296 global $bearsamppBins;
297
298 return TplApp::getActionRun(Action::CHANGE_PORT, array($bearsamppBins->getMysql()->getName())) . PHP_EOL .
300 }
301
302 /**
303 * Generates the action to change MySQL root password.
304 *
305 * This method creates the action string for changing the MySQL root password.
306 *
307 * @global object $bearsamppBins Provides access to system binaries and their configurations.
308 *
309 * @return string The generated action string for changing MySQL root password.
310 */
311 public static function getActionChangeMysqlRootPwd()
312 {
313 global $bearsamppBins;
314
315 return TplApp::getActionRun(Action::CHANGE_DB_ROOT_PWD, array($bearsamppBins->getMysql()->getName())) . PHP_EOL .
317 }
318
319 /**
320 * Generates the action to install MySQL service.
321 *
322 * This method creates the action string for installing the MySQL service.
323 *
324 * @return string The generated action string for installing MySQL service.
325 */
331
332 /**
333 * Generates the action to remove MySQL service.
334 *
335 * This method creates the action string for removing the MySQL service.
336 *
337 * @return string The generated action string for removing MySQL service.
338 */
344}
$result
global $bearsamppBins
global $bearsamppLang
const CHANGE_PORT
const DEBUG_MYSQL
const CHECK_PORT
const ENABLE
const SWITCH_VERSION
const SERVICE
const CHANGE_DB_ROOT_PWD
const CMD_VARIABLES
const CMD_VERSION
const CMD_SYNTAX_CHECK
const SERVICE_NAME
const DISABLED
const ENABLED
const DEBUG_MYSQL_VERSION
const MENU_ERROR_LOGS
const MYSQL
const VERSIONS
const DEBUG_MYSQL_VARIABLES
const MENU_INSTALL_SERVICE
const MENU_CHANGE_ROOT_PWD
const DEBUG_MYSQL_SYNTAX_CHECK
const DEBUG
const MENU_ENABLE
const DOWNLOAD_MORE
const MENU_REMOVE_SERVICE
const CONSOLE
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 getMenuMysqlService()
static getActionInstallMysqlService()
static getActionChangeMysqlRootPwd()
static getActionEnableMysql($enable)
static getActionChangeMysqlPort()
static getMenuMysqlVersions()
static getActionSwitchMysqlVersion($version)
static getActionRemoveMysqlService()
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)