Bearsampp 2026.3.26
API documentation
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
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
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::getItemPowerShell(
104 $bearsamppLang->getValue(Lang::CONSOLE),
106 null,
107 $bearsamppTools->getPowerShell()->getTabTitleMysql(),
108 $bearsamppBins->getMysql()->getSymlinkPath(),
109 null
110 ) . PHP_EOL;
111
112 // Conf
113 $resultItems .= TplAestan::getItemNotepad(basename($bearsamppBins->getMysql()->getConf()), $bearsamppBins->getMysql()->getConf()) . PHP_EOL;
114
115 // Errors log
116 $resultItems .= TplAestan::getItemNotepad($bearsamppLang->getValue(Lang::MENU_ERROR_LOGS), $bearsamppBins->getMysql()->getErrorLog()) . PHP_EOL;
117 }
118
119 return $resultItems . PHP_EOL . $resultActions;
120 }
121
131 public static function getMenuMysqlVersions()
132 {
133 global $bearsamppBins;
134 $items = '';
135 $actions = '';
136
137 foreach ($bearsamppBins->getMysql()->getVersionList() as $version) {
138 $tplSwitchMysqlVersion = TplApp::getActionMulti(
139 self::ACTION_SWITCH_VERSION, array($version),
140 array($version, $version == $bearsamppBins->getMysql()->getVersion() ? TplAestan::GLYPH_CHECK : ''),
141 false, get_called_class()
142 );
143
144 // Item
145 $items .= $tplSwitchMysqlVersion[TplApp::SECTION_CALL] . PHP_EOL;
146
147 // Action
148 $actions .= PHP_EOL . $tplSwitchMysqlVersion[TplApp::SECTION_CONTENT];
149 }
150
151 return $items . $actions;
152 }
153
164 public static function getActionEnableMysql($enable)
165 {
166 global $bearsamppBins;
167
168 return TplApp::getActionRun(Action::ENABLE, array($bearsamppBins->getMysql()->getName(), $enable)) . PHP_EOL .
170 }
171
182 public static function getActionSwitchMysqlVersion($version)
183 {
184 global $bearsamppBins;
185
186 return TplApp::getActionRun(Action::SWITCH_VERSION, array($bearsamppBins->getMysql()->getName(), $version)) . PHP_EOL .
188 }
189
201 public static function getMenuMysqlService()
202 {
204
205 $tplChangePort = TplApp::getActionMulti(
206 self::ACTION_CHANGE_PORT, null,
208 false, get_called_class()
209 );
210
211 $isInstalled = $bearsamppBins->getMysql()->getService()->isInstalled();
212
213 $result = TplAestan::getItemActionServiceStart($bearsamppBins->getMysql()->getService()->getName()) . PHP_EOL .
214 TplAestan::getItemActionServiceStop($bearsamppBins->getMysql()->getService()->getName()) . PHP_EOL .
215 TplAestan::getItemActionServiceRestart($bearsamppBins->getMysql()->getService()->getName()) . PHP_EOL .
216 TplAestan::getItemSeparator() . PHP_EOL .
218 Action::CHECK_PORT, array($bearsamppBins->getMysql()->getName(), $bearsamppBins->getMysql()->getPort()),
219 array(sprintf($bearsamppLang->getValue(Lang::MENU_CHECK_PORT), $bearsamppBins->getMysql()->getPort()), TplAestan::GLYPH_LIGHT)
220 ) . PHP_EOL .
221 $tplChangePort[TplApp::SECTION_CALL] . PHP_EOL;
222
223 $tplChangeRootPwd = null;
224 if ($isInstalled) {
225 $tplChangeRootPwd = TplApp::getActionMulti(
226 self::ACTION_CHANGE_ROOT_PWD, null,
228 !$isInstalled, get_called_class()
229 );
230
231 $result .= $tplChangeRootPwd[TplApp::SECTION_CALL] . PHP_EOL;
232 }
233
234 if (!$isInstalled) {
235 $tplInstallService = TplApp::getActionMulti(
236 self::ACTION_INSTALL_SERVICE, null,
238 $isInstalled, get_called_class()
239 );
240
241 $result .= $tplInstallService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
242 $tplInstallService[TplApp::SECTION_CONTENT] . PHP_EOL;
243 } else {
244 $tplRemoveService = TplApp::getActionMulti(
245 self::ACTION_REMOVE_SERVICE, null,
247 !$isInstalled, get_called_class()
248 );
249
250 $result .= $tplRemoveService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
251 $tplRemoveService[TplApp::SECTION_CONTENT] . PHP_EOL;
252 }
253
254 $result .= $tplChangePort[TplApp::SECTION_CONTENT] . PHP_EOL .
255 ($tplChangeRootPwd != null ? $tplChangeRootPwd[TplApp::SECTION_CONTENT] . PHP_EOL : '');
256
257 return $result;
258 }
259
287
297 public static function getActionChangeMysqlPort()
298 {
299 global $bearsamppBins;
300
301 return TplApp::getActionRun(Action::CHANGE_PORT, array($bearsamppBins->getMysql()->getName())) . PHP_EOL .
303 }
304
314 public static function getActionChangeMysqlRootPwd()
315 {
316 global $bearsamppBins;
317
318 return TplApp::getActionRun(Action::CHANGE_DB_ROOT_PWD, array($bearsamppBins->getMysql()->getName())) . PHP_EOL .
320 }
321
334
347}
$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
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 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()
static getWebsiteUrl($path='', $fragment='', $utmSource=true)