2024.8.23
Loading...
Searching...
No Matches
ActionSwitchVersion Class Reference

Public Member Functions

 __construct ($args)
 
 processWindow ($window, $id, $ctrl, $param1, $param2)
 

Data Fields

const GAUGE_OTHERS = 7
 
const GAUGE_SERVICES = 1
 

Private Attributes

 $bearsamppSplash
 
 $bin
 
 $boxTitle
 
 $changePort
 
 $currentVersion
 
 $service
 
 $version
 

Detailed Description

Class ActionSwitchVersion Handles the switching of versions for various services and binaries in the Bearsampp application.

Definition at line 14 of file class.action.switchVersion.php.

Constructor & Destructor Documentation

◆ __construct()

ActionSwitchVersion::__construct ( $args)

ActionSwitchVersion constructor. Initializes the class with the provided arguments and sets up the splash screen.

Parameters
array$argsCommand line arguments for switching versions.

Definition at line 33 of file class.action.switchVersion.php.

34 {
35 global $bearsamppLang, $bearsamppBins, $bearsamppWinbinder;
36
37 if (isset($args[0]) && !empty($args[0]) && isset($args[1]) && !empty($args[1])) {
38 $this->pathsToScan = array();
39 $this->version = $args[1];
40
41 if ($args[0] == $bearsamppBins->getApache()->getName()) {
42 $this->bin = $bearsamppBins->getApache();
43 $this->currentVersion = $bearsamppBins->getApache()->getVersion();
44 $this->service = $bearsamppBins->getApache()->getService();
45 $this->changePort = true;
46 $folderList = Util::getFolderList($bearsamppBins->getApache()->getRootPath());
47 foreach ($folderList as $folder) {
48 $this->pathsToScan[] = array(
49 'path' => $bearsamppBins->getApache()->getRootPath() . '/' . $folder,
50 'includes' => array('.ini', '.conf'),
51 'recursive' => true
52 );
53 }
54 } elseif ($args[0] == $bearsamppBins->getPhp()->getName()) {
55 $this->bin = $bearsamppBins->getPhp();
56 $this->currentVersion = $bearsamppBins->getPhp()->getVersion();
57 $this->service = $bearsamppBins->getApache()->getService();
58 $this->changePort = false;
59 $folderList = Util::getFolderList($bearsamppBins->getPhp()->getRootPath());
60 foreach ($folderList as $folder) {
61 $this->pathsToScan[] = array(
62 'path' => $bearsamppBins->getPhp()->getRootPath() . '/' . $folder,
63 'includes' => array('.php', '.bat', '.ini', '.reg', '.inc'),
64 'recursive' => true
65 );
66 }
67 } elseif ($args[0] == $bearsamppBins->getMysql()->getName()) {
68 $this->bin = $bearsamppBins->getMysql();
69 $this->currentVersion = $bearsamppBins->getMysql()->getVersion();
70 $this->service = $bearsamppBins->getMysql()->getService();
71 $this->changePort = true;
72 $folderList = Util::getFolderList($bearsamppBins->getMysql()->getRootPath());
73 foreach ($folderList as $folder) {
74 $this->pathsToScan[] = array(
75 'path' => $bearsamppBins->getMysql()->getRootPath() . '/' . $folder,
76 'includes' => array('my.ini'),
77 'recursive' => false
78 );
79 }
80 } elseif ($args[0] == $bearsamppBins->getMariadb()->getName()) {
81 $this->bin = $bearsamppBins->getMariadb();
82 $this->currentVersion = $bearsamppBins->getMariadb()->getVersion();
83 $this->service = $bearsamppBins->getMariadb()->getService();
84 $this->changePort = true;
85 $folderList = Util::getFolderList($bearsamppBins->getMariadb()->getRootPath());
86 foreach ($folderList as $folder) {
87 $this->pathsToScan[] = array(
88 'path' => $bearsamppBins->getMariadb()->getRootPath() . '/' . $folder,
89 'includes' => array('my.ini'),
90 'recursive' => false
91 );
92 }
93 } elseif ($args[0] == $bearsamppBins->getPostgresql()->getName()) {
94 $this->bin = $bearsamppBins->getPostgresql();
95 $this->currentVersion = $bearsamppBins->getPostgresql()->getVersion();
96 $this->service = $bearsamppBins->getPostgresql()->getService();
97 $this->changePort = true;
98 $folderList = Util::getFolderList($bearsamppBins->getPostgresql()->getRootPath());
99 foreach ($folderList as $folder) {
100 $this->pathsToScan[] = array(
101 'path' => $bearsamppBins->getPostgresql()->getRootPath() . '/' . $folder,
102 'includes' => array('.ber', '.conf', '.bat'),
103 'recursive' => true
104 );
105 }
106 } elseif ($args[0] == $bearsamppBins->getNodejs()->getName()) {
107 $this->bin = $bearsamppBins->getNodejs();
108 $this->currentVersion = $bearsamppBins->getNodejs()->getVersion();
109 $this->service = null;
110 $this->changePort = false;
111 $folderList = Util::getFolderList($bearsamppBins->getNodejs()->getRootPath());
112 foreach ($folderList as $folder) {
113 $this->pathsToScan[] = array(
114 'path' => $bearsamppBins->getNodejs()->getRootPath() . '/' . $folder . '/etc',
115 'includes' => array('npmrc'),
116 'recursive' => true
117 );
118 $this->pathsToScan[] = array(
119 'path' => $bearsamppBins->getNodejs()->getRootPath() . '/' . $folder . '/node_modules/npm',
120 'includes' => array('npmrc'),
121 'recursive' => false
122 );
123 }
124 } elseif ($args[0] == $bearsamppBins->getFilezilla()->getName()) {
125 $this->bin = $bearsamppBins->getFilezilla();
126 $this->currentVersion = $bearsamppBins->getFilezilla()->getVersion();
127 $this->service = $bearsamppBins->getFilezilla()->getService();
128 $this->changePort = true;
129 $folderList = Util::getFolderList($bearsamppBins->getFilezilla()->getRootPath());
130 foreach ($folderList as $folder) {
131 $this->pathsToScan[] = array(
132 'path' => $bearsamppBins->getFilezilla()->getRootPath() . '/' . $folder,
133 'includes' => array('.xml'),
134 'recursive' => true
135 );
136 }
137 } elseif ($args[0] == $bearsamppBins->getMemcached()->getName()) {
138 $this->bin = $bearsamppBins->getMemcached();
139 $this->currentVersion = $bearsamppBins->getMemcached()->getVersion();
140 $this->service = $bearsamppBins->getMemcached()->getService();
141 $this->changePort = true;
142 }
143
144 $this->boxTitle = sprintf($bearsamppLang->getValue(Lang::SWITCH_VERSION_TITLE), $this->bin->getName(), $this->version);
145
146 // Start splash screen
147 $this->bearsamppSplash = new Splash();
148 $this->bearsamppSplash->init(
149 $this->boxTitle,
150 self::GAUGE_SERVICES * count($bearsamppBins->getServices()) + self::GAUGE_OTHERS,
151 $this->boxTitle
152 );
153
154 $bearsamppWinbinder->setHandler($this->bearsamppSplash->getWbWindow(), $this, 'processWindow', 1000);
155 $bearsamppWinbinder->mainLoop();
156 $bearsamppWinbinder->reset();
157 }
158 }
global $bearsamppBins
global $bearsamppLang
const SWITCH_VERSION_TITLE
static getFolderList($path)

References $bearsamppBins, $bearsamppLang, Util\getFolderList(), and Lang\SWITCH_VERSION_TITLE.

Member Function Documentation

◆ processWindow()

ActionSwitchVersion::processWindow ( $window,
$id,
$ctrl,
$param1,
$param2 )

Processes the window events for the splash screen.

Parameters
mixed$windowThe window handle.
int$idThe event ID.
mixed$ctrlThe control handle.
mixed$param1The first parameter.
mixed$param2The second parameter.

Definition at line 169 of file class.action.switchVersion.php.

170 {
171 global $bearsamppCore, $bearsamppLang, $bearsamppBins, $bearsamppWinbinder;
172
173 if ($this->version == $this->currentVersion) {
174 $bearsamppWinbinder->messageBoxWarning(sprintf($bearsamppLang->getValue(Lang::SWITCH_VERSION_SAME_ERROR), $this->bin->getName(), $this->version), $this->boxTitle);
175 $bearsamppWinbinder->destroyWindow($window);
176 }
177
178 // scan folder
179 $this->bearsamppSplash->incrProgressBar();
180 if (!empty($this->pathsToScan)) {
181 Util::changePath(Util::getFilesToScan($this->pathsToScan));
182 }
183
184 // switch
185 $this->bearsamppSplash->incrProgressBar();
186 if ($this->bin->switchVersion($this->version, true) === false) {
187 $this->bearsamppSplash->incrProgressBar(self::GAUGE_SERVICES * count($bearsamppBins->getServices()) + self::GAUGE_OTHERS);
188 $bearsamppWinbinder->destroyWindow($window);
189 }
190
191 // stop service
192 if ($this->service != null) {
193 $binName = $this->bin->getName() == $bearsamppLang->getValue(Lang::PHP) ? $bearsamppLang->getValue(Lang::APACHE) : $this->bin->getName();
194 $this->bearsamppSplash->setTextLoading(sprintf($bearsamppLang->getValue(Lang::STOP_SERVICE_TITLE), $binName));
195 $this->bearsamppSplash->incrProgressBar();
196 $this->service->stop();
197 } else {
198 $this->bearsamppSplash->incrProgressBar();
199 }
200
201 // reload config
202 $this->bearsamppSplash->setTextLoading($bearsamppLang->getValue(Lang::SWITCH_VERSION_RELOAD_CONFIG));
203 $this->bearsamppSplash->incrProgressBar();
205
206 // reload bins
207 $this->bearsamppSplash->setTextLoading($bearsamppLang->getValue(Lang::SWITCH_VERSION_RELOAD_BINS));
208 $this->bearsamppSplash->incrProgressBar();
209 $bearsamppBins->reload();
210
211 // change port
212 if ($this->changePort) {
213 $this->bin->reload();
214 $this->bin->changePort($this->bin->getPort());
215 }
216
217 // start service
218 if ($this->service != null) {
219 $binName = $this->bin->getName() == $bearsamppLang->getValue(Lang::PHP) ? $bearsamppLang->getValue(Lang::APACHE) : $this->bin->getName();
220 $this->bearsamppSplash->setTextLoading(sprintf($bearsamppLang->getValue(Lang::START_SERVICE_TITLE), $binName));
221 $this->bearsamppSplash->incrProgressBar();
222 $this->service->start();
223 } else {
224 $this->bearsamppSplash->incrProgressBar();
225 }
226
227 $this->bearsamppSplash->incrProgressBar(self::GAUGE_SERVICES * count($bearsamppBins->getServices()) + 1);
228 $bearsamppWinbinder->messageBoxInfo(
229 sprintf($bearsamppLang->getValue(Lang::SWITCH_VERSION_OK), $this->bin->getName(), $this->version),
230 $this->boxTitle);
231 $bearsamppWinbinder->destroyWindow($window);
232
233 $this->bearsamppSplash->setTextLoading(sprintf($bearsamppLang->getValue(Lang::SWITCH_VERSION_REGISTRY), Registry::APP_BINS_REG_ENTRY));
234 $this->bearsamppSplash->incrProgressBar(2);
236
237 $this->bearsamppSplash->setTextLoading($bearsamppLang->getValue(Lang::SWITCH_VERSION_RESET_SERVICES));
238 foreach ($bearsamppBins->getServices() as $sName => $service) {
239 $this->bearsamppSplash->incrProgressBar();
240 $service->delete();
241 }
242
243 $bearsamppWinbinder->messageBoxInfo(
244 sprintf($bearsamppLang->getValue(Lang::SWITCH_VERSION_OK_RESTART), $this->bin->getName(), $this->version, APP_TITLE),
245 $this->boxTitle);
246
248
249 $bearsamppWinbinder->destroyWindow($window);
250 }
global $bearsamppCore
const START_SERVICE_TITLE
const SWITCH_VERSION_OK
const SWITCH_VERSION_REGISTRY
const SWITCH_VERSION_SAME_ERROR
const SWITCH_VERSION_RELOAD_CONFIG
const PHP
const APACHE
const SWITCH_VERSION_RESET_SERVICES
const SWITCH_VERSION_RELOAD_BINS
const SWITCH_VERSION_OK_RESTART
const STOP_SERVICE_TITLE
const APP_BINS_REG_ENTRY
static loadConfig()
static getFilesToScan($path=null)
static changePath($filesToScan, $rootPath=null)
static setAppBinsRegKey($value)
static getAppBinsRegKey($fromRegistry=true)
const APP_TITLE
Definition root.php:12

References $bearsamppBins, $bearsamppCore, $bearsamppLang, $service, Lang\APACHE, Registry\APP_BINS_REG_ENTRY, APP_TITLE, Util\changePath(), Util\getAppBinsRegKey(), Util\getFilesToScan(), Root\loadConfig(), Lang\PHP, ActionExec\RESTART, Util\setAppBinsRegKey(), Lang\START_SERVICE_TITLE, Lang\STOP_SERVICE_TITLE, Lang\SWITCH_VERSION_OK, Lang\SWITCH_VERSION_OK_RESTART, Lang\SWITCH_VERSION_REGISTRY, Lang\SWITCH_VERSION_RELOAD_BINS, Lang\SWITCH_VERSION_RELOAD_CONFIG, Lang\SWITCH_VERSION_RESET_SERVICES, and Lang\SWITCH_VERSION_SAME_ERROR.

Field Documentation

◆ $bearsamppSplash

ActionSwitchVersion::$bearsamppSplash
private

Definition at line 16 of file class.action.switchVersion.php.

◆ $bin

ActionSwitchVersion::$bin
private

Definition at line 18 of file class.action.switchVersion.php.

◆ $boxTitle

ActionSwitchVersion::$boxTitle
private

Definition at line 22 of file class.action.switchVersion.php.

◆ $changePort

ActionSwitchVersion::$changePort
private

Definition at line 21 of file class.action.switchVersion.php.

◆ $currentVersion

ActionSwitchVersion::$currentVersion
private

Definition at line 19 of file class.action.switchVersion.php.

◆ $service

ActionSwitchVersion::$service
private

Definition at line 20 of file class.action.switchVersion.php.

Referenced by processWindow().

◆ $version

ActionSwitchVersion::$version
private

Definition at line 17 of file class.action.switchVersion.php.

◆ GAUGE_OTHERS

const ActionSwitchVersion::GAUGE_OTHERS = 7

Definition at line 25 of file class.action.switchVersion.php.

◆ GAUGE_SERVICES

const ActionSwitchVersion::GAUGE_SERVICES = 1

Definition at line 24 of file class.action.switchVersion.php.


The documentation for this class was generated from the following file: