Bearsampp 2026.9.23
Loading...
Searching...
No Matches
class.tpl.app.mysql.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 // 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
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
61 public static function getMenuMysql()
62 {
63 global $bearsamppBins, $bearsamppLang, $bearsamppTools;
64 $resultItems = $resultActions = '';
65
66 $isEnabled = $bearsamppBins->getMysql()->isEnable();
67
68 // Download
69 $resultItems .= TplAestan::getItemLink(
71 HttpClient::getWebsiteUrl('module/mysql', '#releases'),
72 false,
74 ) . PHP_EOL;
75
76 // Enable
77 $tplEnable = TplApp::getActionMulti(
78 self::ACTION_ENABLE,
79 array($isEnabled ? Config::DISABLED : Config::ENABLED),
80 array($bearsamppLang->getValue(Lang::MENU_ENABLE), $isEnabled ? TplAestan::GLYPH_CHECK : ''),
81 false,
82 get_called_class()
83 );
84 $resultItems .= $tplEnable[TplApp::SECTION_CALL] . PHP_EOL;
85 $resultActions .= $tplEnable[TplApp::SECTION_CONTENT] . PHP_EOL;
86
87 if ($isEnabled) {
88 $resultItems .= TplAestan::getItemSeparator() . PHP_EOL;
89
90 // Versions
91 $tplVersions = TplApp::getMenu($bearsamppLang->getValue(Lang::VERSIONS), self::MENU_VERSIONS, get_called_class());
92 $resultItems .= $tplVersions[TplApp::SECTION_CALL] . PHP_EOL;
93 $resultActions .= $tplVersions[TplApp::SECTION_CONTENT] . PHP_EOL;
94
95 // Service
96 $tplService = TplApp::getMenu($bearsamppLang->getValue(Lang::SERVICE), self::MENU_SERVICE, get_called_class());
97 $resultItems .= $tplService[TplApp::SECTION_CALL] . PHP_EOL;
98 $resultActions .= $tplService[TplApp::SECTION_CONTENT] . PHP_EOL;
99
100 // Debug
101 $tplDebug = TplApp::getMenu($bearsamppLang->getValue(Lang::DEBUG), self::MENU_DEBUG, get_called_class());
102 $resultItems .= $tplDebug[TplApp::SECTION_CALL] . PHP_EOL;
103 $resultActions .= $tplDebug[TplApp::SECTION_CONTENT];
104
105 // Console
106 $resultItems .= TplAestan::getItemPowerShell(
107 $bearsamppLang->getValue(Lang::CONSOLE),
109 null,
110 $bearsamppTools->getPowerShell()->getTabTitleMysql(),
112 null
113 ) . PHP_EOL;
114
115 // Conf
116 $resultItems .= TplAestan::getItemNotepad(basename($bearsamppBins->getMysql()->getConf()), $bearsamppBins->getMysql()->getConf()) . PHP_EOL;
117
118 // Errors log
119 $resultItems .= TplAestan::getItemNotepad($bearsamppLang->getValue(Lang::MENU_ERROR_LOGS), $bearsamppBins->getMysql()->getErrorLog()) . PHP_EOL;
120 }
121
122 return $resultItems . PHP_EOL . $resultActions;
123 }
124
134 public static function getMenuMysqlVersions()
135 {
136 global $bearsamppBins;
137 $items = '';
138 $actions = '';
139
140 foreach ($bearsamppBins->getMysql()->getVersionList() as $version) {
141 $tplSwitchMysqlVersion = TplApp::getActionMulti(
142 self::ACTION_SWITCH_VERSION,
143 array($version),
144 array($version, $version == $bearsamppBins->getMysql()->getVersion() ? TplAestan::GLYPH_CHECK : ''),
145 false,
146 get_called_class()
147 );
148
149 // Item
150 $items .= $tplSwitchMysqlVersion[TplApp::SECTION_CALL] . PHP_EOL;
151
152 // Action
153 $actions .= PHP_EOL . $tplSwitchMysqlVersion[TplApp::SECTION_CONTENT];
154 }
155
156 return $items . $actions;
157 }
158
170 public static function getActionEnableMysql($enable)
171 {
172 global $bearsamppBins;
173
174 return TplApp::getActionRun(Action::ENABLE, array($bearsamppBins->getMysql()->getName(), $enable)) . PHP_EOL .
176 }
177
189 public static function getActionSwitchMysqlVersion($version)
190 {
191 global $bearsamppBins;
192
193 return TplApp::getActionRun(Action::SWITCH_VERSION, array($bearsamppBins->getMysql()->getName(), $version)) . PHP_EOL .
195 }
196
208 public static function getMenuMysqlService()
209 {
211
212 $tplChangePort = TplApp::getActionMulti(
213 self::ACTION_CHANGE_PORT,
214 null,
216 false,
217 get_called_class()
218 );
219
220 $isInstalled = $bearsamppBins->getMysql()->getService()->isInstalled();
221
222 $result = TplAestan::getItemActionServiceStart($bearsamppBins->getMysql()->getService()->getName()) . PHP_EOL .
223 TplAestan::getItemActionServiceStop($bearsamppBins->getMysql()->getService()->getName()) . PHP_EOL .
224 TplAestan::getItemActionServiceRestart($bearsamppBins->getMysql()->getService()->getName()) . PHP_EOL .
225 TplAestan::getItemSeparator() . PHP_EOL .
228 array($bearsamppBins->getMysql()->getName(), $bearsamppBins->getMysql()->getPort()),
229 array(sprintf($bearsamppLang->getValue(Lang::MENU_CHECK_PORT), $bearsamppBins->getMysql()->getPort()), TplAestan::GLYPH_LIGHT)
230 ) . PHP_EOL .
231 $tplChangePort[TplApp::SECTION_CALL] . PHP_EOL;
232
233 $tplChangeRootPwd = null;
234 if ($isInstalled) {
235 $tplChangeRootPwd = TplApp::getActionMulti(
236 self::ACTION_CHANGE_ROOT_PWD,
237 null,
239 !$isInstalled,
240 get_called_class()
241 );
242
243 $result .= $tplChangeRootPwd[TplApp::SECTION_CALL] . PHP_EOL;
244 }
245
246 if (!$isInstalled) {
247 $tplInstallService = TplApp::getActionMulti(
248 self::ACTION_INSTALL_SERVICE,
249 null,
251 $isInstalled,
252 get_called_class()
253 );
254
255 $result .= $tplInstallService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
256 $tplInstallService[TplApp::SECTION_CONTENT] . PHP_EOL;
257 } else {
258 $tplRemoveService = TplApp::getActionMulti(
259 self::ACTION_REMOVE_SERVICE,
260 null,
262 !$isInstalled,
263 get_called_class()
264 );
265
266 $result .= $tplRemoveService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
267 $tplRemoveService[TplApp::SECTION_CONTENT] . PHP_EOL;
268 }
269
270 $result .= $tplChangePort[TplApp::SECTION_CONTENT] . PHP_EOL .
271 ($tplChangeRootPwd != null ? $tplChangeRootPwd[TplApp::SECTION_CONTENT] . PHP_EOL : '');
272
273 return $result;
274 }
275
306
316 public static function getActionChangeMysqlPort()
317 {
318 global $bearsamppBins;
319
320 return TplApp::getActionRun(Action::CHANGE_PORT, array($bearsamppBins->getMysql()->getName())) . PHP_EOL .
322 }
323
333 public static function getActionChangeMysqlRootPwd()
334 {
335 global $bearsamppBins;
336
337 return TplApp::getActionRun(Action::CHANGE_DB_ROOT_PWD, array($bearsamppBins->getMysql()->getName())) . PHP_EOL .
339 }
340
353
366}
$result
global $bearsamppBins
global $bearsamppLang
const SWITCH_VERSION
const CHANGE_DB_ROOT_PWD
const DEBUG_MYSQL
const SERVICE
const CHANGE_PORT
const CHECK_PORT
const ENABLE
const SERVICE_NAME
const CMD_SYNTAX_CHECK
const CMD_VERSION
const CMD_VARIABLES
const DISABLED
const ENABLED
static getWebsiteUrl($path='', $fragment='', $utmSource=true)
const MENU_ENABLE
const DEBUG_MYSQL_SYNTAX_CHECK
const MENU_CHANGE_ROOT_PWD
const SERVICE
const DOWNLOAD_MORE
const CONSOLE
const MENU_CHANGE_PORT
const DEBUG
const MENU_ERROR_LOGS
const MENU_INSTALL_SERVICE
const DEBUG_MYSQL_VERSION
const MYSQL
const DEBUG_MYSQL_VARIABLES
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 getActionRemoveMysqlService()
static getMenuMysqlService()
static getActionChangeMysqlRootPwd()
static getActionEnableMysql($enable)
static getActionChangeMysqlPort()
static getMenuMysqlVersions()
static getActionSwitchMysqlVersion($version)
static getActionInstallMysqlService()