Bearsampp 2025.8.29
Loading...
Searching...
No Matches
ActionSwitchVersion Class Reference

Public Member Functions

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

Data Fields

const CONFIG_KEY_VERSION = 'version'
const CONFIG_SECTION_APACHE = 'apache'
const CONFIG_SECTION_MAILPIT = 'mailpit'
const CONFIG_SECTION_MARIADB = 'mariadb'
const CONFIG_SECTION_MEMCACHED = 'memcached'
const CONFIG_SECTION_MYSQL = 'mysql'
const CONFIG_SECTION_NODEJS = 'nodejs'
const CONFIG_SECTION_PHP = 'php'
const CONFIG_SECTION_POSTGRESQL = 'postgresql'
const CONFIG_SECTION_XLIGHT = 'xlight'
const GAUGE_OTHERS = 7
const GAUGE_SERVICES = 1

Private Member Functions

 updateConfigVersion ()

Private Attributes

 $bearsamppSplash
 $bin
 $boxTitle
 $changePort
 $currentVersion
 $pathsToScan = []
 $service
 $version

Detailed Description

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

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

Constructor & Destructor Documentation

◆ __construct()

__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 49 of file class.action.switchVersion.php.

50 {
51 global $bearsamppLang, $bearsamppBins, $bearsamppWinbinder;
52
53 if (isset($args[0]) && !empty($args[0]) && isset($args[1]) && !empty($args[1])) {
54 $this->pathsToScan = array();
55 $this->version = $args[1];
56
57 if ($args[0] == $bearsamppBins->getApache()->getName()) {
58 $this->bin = $bearsamppBins->getApache();
59 $this->currentVersion = $bearsamppBins->getApache()->getVersion();
60 $this->service = $bearsamppBins->getApache()->getService();
61 $this->changePort = true;
62 $folderList = Util::getFolderList($bearsamppBins->getApache()->getRootPath());
63 foreach ($folderList as $folder) {
64 $this->pathsToScan[] = array(
65 'path' => $bearsamppBins->getApache()->getRootPath() . '/' . $folder,
66 'includes' => array('.ini', '.conf'),
67 'recursive' => true
68 );
69 }
70 } elseif ($args[0] == $bearsamppBins->getPhp()->getName()) {
71 $this->bin = $bearsamppBins->getPhp();
72 $this->currentVersion = $bearsamppBins->getPhp()->getVersion();
73 $this->service = $bearsamppBins->getApache()->getService();
74 $this->changePort = false;
75 $folderList = Util::getFolderList($bearsamppBins->getPhp()->getRootPath());
76 foreach ($folderList as $folder) {
77 $this->pathsToScan[] = array(
78 'path' => $bearsamppBins->getPhp()->getRootPath() . '/' . $folder,
79 'includes' => array('.php', '.bat', '.ini', '.reg', '.inc'),
80 'recursive' => true
81 );
82 }
83 } elseif ($args[0] == $bearsamppBins->getMysql()->getName()) {
84 $this->bin = $bearsamppBins->getMysql();
85 $this->currentVersion = $bearsamppBins->getMysql()->getVersion();
86 $this->service = $bearsamppBins->getMysql()->getService();
87 $this->changePort = true;
88 $folderList = Util::getFolderList($bearsamppBins->getMysql()->getRootPath());
89 foreach ($folderList as $folder) {
90 $this->pathsToScan[] = array(
91 'path' => $bearsamppBins->getMysql()->getRootPath() . '/' . $folder,
92 'includes' => array('my.ini'),
93 'recursive' => false
94 );
95 }
96 } elseif ($args[0] == $bearsamppBins->getMariadb()->getName()) {
97 $this->bin = $bearsamppBins->getMariadb();
98 $this->currentVersion = $bearsamppBins->getMariadb()->getVersion();
99 $this->service = $bearsamppBins->getMariadb()->getService();
100 $this->changePort = true;
101 $folderList = Util::getFolderList($bearsamppBins->getMariadb()->getRootPath());
102 foreach ($folderList as $folder) {
103 $this->pathsToScan[] = array(
104 'path' => $bearsamppBins->getMariadb()->getRootPath() . '/' . $folder,
105 'includes' => array('my.ini'),
106 'recursive' => false
107 );
108 }
109 } elseif ($args[0] == $bearsamppBins->getPostgresql()->getName()) {
110 $this->bin = $bearsamppBins->getPostgresql();
111 $this->currentVersion = $bearsamppBins->getPostgresql()->getVersion();
112 $this->service = $bearsamppBins->getPostgresql()->getService();
113 $this->changePort = true;
114 $folderList = Util::getFolderList($bearsamppBins->getPostgresql()->getRootPath());
115 foreach ($folderList as $folder) {
116 $this->pathsToScan[] = array(
117 'path' => $bearsamppBins->getPostgresql()->getRootPath() . '/' . $folder,
118 'includes' => array('.ber', '.conf', '.bat'),
119 'recursive' => true
120 );
121 }
122 } elseif ($args[0] == $bearsamppBins->getNodejs()->getName()) {
123 $this->bin = $bearsamppBins->getNodejs();
124 $this->currentVersion = $bearsamppBins->getNodejs()->getVersion();
125 $this->service = null;
126 $this->changePort = false;
127 $folderList = Util::getFolderList($bearsamppBins->getNodejs()->getRootPath());
128 foreach ($folderList as $folder) {
129 $this->pathsToScan[] = array(
130 'path' => $bearsamppBins->getNodejs()->getRootPath() . '/' . $folder . '/etc',
131 'includes' => array('npmrc'),
132 'recursive' => true
133 );
134 $this->pathsToScan[] = array(
135 'path' => $bearsamppBins->getNodejs()->getRootPath() . '/' . $folder . '/node_modules/npm',
136 'includes' => array('npmrc'),
137 'recursive' => false
138 );
139 }
140 } elseif ($args[0] == $bearsamppBins->getMemcached()->getName()) {
141 $this->bin = $bearsamppBins->getMemcached();
142 $this->currentVersion = $bearsamppBins->getMemcached()->getVersion();
143 $this->service = $bearsamppBins->getMemcached()->getService();
144 $this->changePort = true;
145 } elseif ($args[0] == $bearsamppBins->getMailpit()->getName()) {
146 $this->bin = $bearsamppBins->getMailpit();
147 $this->currentVersion = $bearsamppBins->getMailpit()->getVersion();
148 $this->service = $bearsamppBins->getMailpit()->getService();
149 $this->changePort = false;
150 $folderList = Util::getFolderList($bearsamppBins->getMailpit()->getRootPath());
151 foreach ($folderList as $folder) {
152 $this->pathsToScan[] = array(
153 'path' => $bearsamppBins->getMailpit()->getRootPath() . '/' . $folder,
154 'includes' => array('.conf'),
155 'recursive' => true
156 );
157 }
158 } elseif ($args[0] == $bearsamppBins->getXlight()->getName()) {
159 $this->bin = $bearsamppBins->getXlight();
160 $this->currentVersion = $bearsamppBins->getXlight()->getVersion();
161 $this->service = $bearsamppBins->getXlight()->getService();
162 $this->changePort = true;
163 $folderList = Util::getFolderList($bearsamppBins->getXlight()->getRootPath());
164 foreach ($folderList as $folder) {
165 $this->pathsToScan[] = array(
166 'path' => $bearsamppBins->getXlight()->getRootPath() . '/' . $folder,
167 'includes' => array('.conf, ftpd.hosts, ftpd.option, ftpd.password, ftpd.rules, ftpd.users, .ini'),
168 'recursive' => true
169 );
170 }
171 }
172
173 $this->boxTitle = sprintf($bearsamppLang->getValue(Lang::SWITCH_VERSION_TITLE), $this->bin->getName(), $this->version);
174
175 // Start splash screen
176 $this->bearsamppSplash = new Splash();
177 $this->bearsamppSplash->init(
178 $this->boxTitle,
179 self::GAUGE_SERVICES * count($bearsamppBins->getServices()) + self::GAUGE_OTHERS,
180 $this->boxTitle
181 );
182
183 $bearsamppWinbinder->setHandler($this->bearsamppSplash->getWbWindow(), $this, 'processWindow', 1000);
184 $bearsamppWinbinder->mainLoop();
185 $bearsamppWinbinder->reset();
186 }
187 }
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()

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 198 of file class.action.switchVersion.php.

199 {
200 global $bearsamppCore, $bearsamppLang, $bearsamppBins, $bearsamppWinbinder;
201
202 if ($this->version == $this->currentVersion) {
203 $bearsamppWinbinder->messageBoxWarning(sprintf($bearsamppLang->getValue(Lang::SWITCH_VERSION_SAME_ERROR), $this->bin->getName(), $this->version), $this->boxTitle);
204 $bearsamppWinbinder->destroyWindow($window);
205 }
206
207 // scan folder
208 $this->bearsamppSplash->incrProgressBar();
209 if (!empty($this->pathsToScan)) {
210 Util::changePath(Util::getFilesToScan($this->pathsToScan));
211 }
212
213 // switch
214 $this->bearsamppSplash->incrProgressBar();
215 if ($this->bin->switchVersion($this->version, true) === false) {
216 $this->bearsamppSplash->incrProgressBar(self::GAUGE_SERVICES * count($bearsamppBins->getServices()) + self::GAUGE_OTHERS);
217 $bearsamppWinbinder->destroyWindow($window);
218 }
219
220 // stop service
221 if ($this->service != null) {
222 $binName = $this->bin->getName() == $bearsamppLang->getValue(Lang::PHP) ? $bearsamppLang->getValue(Lang::APACHE) : $this->bin->getName();
223 $this->bearsamppSplash->setTextLoading(sprintf($bearsamppLang->getValue(Lang::STOP_SERVICE_TITLE), $binName));
224 $this->bearsamppSplash->incrProgressBar();
225 $this->service->stop();
226 } else {
227 $this->bearsamppSplash->incrProgressBar();
228 }
229
230 // reload config
231 $this->bearsamppSplash->setTextLoading($bearsamppLang->getValue(Lang::SWITCH_VERSION_RELOAD_CONFIG));
232 $this->bearsamppSplash->incrProgressBar();
234
235 // reload bins
236 $this->bearsamppSplash->setTextLoading($bearsamppLang->getValue(Lang::SWITCH_VERSION_RELOAD_BINS));
237 $this->bearsamppSplash->incrProgressBar();
238 $bearsamppBins->reload();
239
240 // change port
241 if ($this->changePort) {
242 $this->bin->reload();
243 $this->bin->changePort($this->bin->getPort());
244 }
245
246 // start service
247 if ($this->service != null) {
248 $binName = $this->bin->getName() == $bearsamppLang->getValue(Lang::PHP) ? $bearsamppLang->getValue(Lang::APACHE) : $this->bin->getName();
249 $this->bearsamppSplash->setTextLoading(sprintf($bearsamppLang->getValue(Lang::START_SERVICE_TITLE), $binName));
250 $this->bearsamppSplash->incrProgressBar();
251 $this->service->start();
252 } else {
253 $this->bearsamppSplash->incrProgressBar();
254 }
255
256 $this->bearsamppSplash->incrProgressBar(self::GAUGE_SERVICES * count($bearsamppBins->getServices()) + 1);
257
258 // Update configuration file with the new version
259 Util::logTrace('Updating ini & menu...');
260 $this->updateConfigVersion();
261
262 Util::logTrace('Creating modal...');
263 $bearsamppWinbinder->messageBoxInfo(
264 sprintf($bearsamppLang->getValue(Lang::SWITCH_VERSION_OK), $this->bin->getName(), $this->version),
265 $this->boxTitle
266 );
267
268 Util::logTrace('Destroying modal window...');
269 $bearsamppWinbinder->destroyWindow($window);
270
271 // Store current registry value for comparison
272 $currentRegValue = Util::getAppBinsRegKey(false);
274
275 Util::logTrace(sprintf(
276 'Starting registry adjustment for key: %s | Current value: %s',
277 $regEntry,
278 $currentRegValue
279 ));
280
281 $this->bearsamppSplash->setTextLoading(sprintf(
283 $regEntry
284 ));
285
286 $this->bearsamppSplash->incrProgressBar(2);
287
288 // Perform the registry update
289 $newRegValue = Util::setAppBinsRegKey($currentRegValue);
290 Util::logTrace(sprintf(
291 'Registry update completed | Key: %s | New value: %s | Previous value: %s',
292 $regEntry,
293 $newRegValue,
294 $currentRegValue
295 ));
296
297 Util::logTrace(sprintf(
298 'Resetting services: %s',
300 ));
301
302 $this->bearsamppSplash->setTextLoading($bearsamppLang->getValue(Lang::SWITCH_VERSION_RESET_SERVICES));
303 foreach ($bearsamppBins->getServices() as $sName => $service) {
304 Util::logTrace(sprintf('Deleting service: %s', $sName));
305 $this->bearsamppSplash->incrProgressBar();
306 $service->delete();
307 Util::logTrace(sprintf('Service deleted: %s', $sName));
308 }
309 Util::logTrace('All services reset completed');
310
311 $bearsamppWinbinder->messageBoxInfo(
312 sprintf($bearsamppLang->getValue(Lang::SWITCH_VERSION_OK_RESTART), $this->bin->getName(), $this->version, APP_TITLE),
313 $this->boxTitle
314 );
315
316 Util::logTrace('Running setExec line 317..');
318
319 Util::logTrace('Destroying final window...');
320 $bearsamppWinbinder->destroyWindow($window);
321 }
global $bearsamppCore
const SWITCH_VERSION_RELOAD_CONFIG
const SWITCH_VERSION_RELOAD_BINS
const START_SERVICE_TITLE
const SWITCH_VERSION_REGISTRY
const SWITCH_VERSION_OK_RESTART
const SWITCH_VERSION_OK
const STOP_SERVICE_TITLE
const PHP
const APACHE
const SWITCH_VERSION_SAME_ERROR
const SWITCH_VERSION_RESET_SERVICES
const APP_BINS_REG_ENTRY
static loadConfig()
static logTrace($data, $file=null)
static getAppBinsRegKey($fromRegistry=true)
static getFilesToScan($path=null)
static changePath($filesToScan, $rootPath=null)
static setAppBinsRegKey($value)
const APP_TITLE
Definition root.php:13

References $bearsamppBins, $bearsamppCore, $bearsamppLang, $service, Lang\APACHE, Registry\APP_BINS_REG_ENTRY, APP_TITLE, Util\changePath(), Util\getAppBinsRegKey(), Util\getFilesToScan(), Root\loadConfig(), Util\logTrace(), 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, Lang\SWITCH_VERSION_SAME_ERROR, and updateConfigVersion().

◆ updateConfigVersion()

updateConfigVersion ( )
private

Updates the configuration file with the new version of the binary This ensures version persistence across restarts

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

327 : void
328 {
329 $bearsamppConfig = new Config();
330 $configSection = '';
331 $version = $this->version; // Ensure version is available in scope
332
333 // Determine the correct configuration section based on binary type
334 if ($this->bin->getName() == $GLOBALS['bearsamppBins']->getApache()->getName()) {
335 $configSection = self::CONFIG_SECTION_APACHE;
336 Util::logTrace(sprintf('Switch %s version to %s', $configSection, $version));
337 } elseif ($this->bin->getName() == $GLOBALS['bearsamppBins']->getPhp()->getName()) {
338 $configSection = self::CONFIG_SECTION_PHP;
339 Util::logTrace(sprintf('Switch %s version to %s', $configSection, $version));
340 } elseif ($this->bin->getName() == $GLOBALS['bearsamppBins']->getMysql()->getName()) {
341 $configSection = self::CONFIG_SECTION_MYSQL;
342 Util::logTrace(sprintf('Switch %s version to %s', $configSection, $version));
343 } elseif ($this->bin->getName() == $GLOBALS['bearsamppBins']->getMariadb()->getName()) {
344 $configSection = self::CONFIG_SECTION_MARIADB;
345 Util::logTrace(sprintf('Switch %s version to %s', $configSection, $version));
346 } elseif ($this->bin->getName() == $GLOBALS['bearsamppBins']->getPostgresql()->getName()) {
347 $configSection = self::CONFIG_SECTION_POSTGRESQL;
348 Util::logTrace(sprintf('Switch %s version to %s', $configSection, $version));
349 } elseif ($this->bin->getName() == $GLOBALS['bearsamppBins']->getNodejs()->getName()) {
350 $configSection = self::CONFIG_SECTION_NODEJS;
351 Util::logTrace(sprintf('Switch %s version to %s', $configSection, $version));
352 } elseif ($this->bin->getName() == $GLOBALS['bearsamppBins']->getMemcached()->getName()) {
353 $configSection = self::CONFIG_SECTION_MEMCACHED;
354 Util::logTrace(sprintf('Switch %s version to %s', $configSection, $version));
355 } elseif ($this->bin->getName() == $GLOBALS['bearsamppBins']->getMailpit()->getName()) {
356 $configSection = self::CONFIG_SECTION_MAILPIT;
357 Util::logTrace(sprintf('Switch %s version to %s', $configSection, $version));
358 } elseif ($this->bin->getName() == $GLOBALS['bearsamppBins']->getXlight()->getName()) {
359 $configSection = self::CONFIG_SECTION_XLIGHT;
360 Util::logTrace(sprintf('Switch %s version to %s', $configSection, $version));
361 }
362
363 // Update the configuration if a valid section was found
364 if (!empty($configSection)) {
365 Util::logTrace('Updating .ini file...');
366 $bearsamppConfig->replace($configSection, self::CONFIG_KEY_VERSION, $version);
367
368 // Update tray menu display if TrayMenu class is available
369 Util::logTrace('Updating TrayMenu...');
370 if (class_exists('TrayMenu')) {
371 $trayMenu = TrayMenu::getInstance();
372 if (method_exists($trayMenu, 'updateSectionVersion')) {
373 $trayMenu->updateSectionVersion(
374 strtoupper($configSection),
376 );
377 }
378 }
379 }
380 Util::logTrace('Returning to parent call');
381 }
global $bearsamppConfig
Definition homepage.php:27

References $bearsamppConfig, $version, and Util\logTrace().

Referenced by processWindow().

Field Documentation

◆ $bearsamppSplash

$bearsamppSplash
private

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

◆ $bin

$bin
private

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

◆ $boxTitle

$boxTitle
private

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

◆ $changePort

$changePort
private

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

◆ $currentVersion

$currentVersion
private

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

◆ $pathsToScan

$pathsToScan = []
private

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

◆ $service

$service
private

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

Referenced by processWindow().

◆ $version

$version
private

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

Referenced by updateConfigVersion().

◆ CONFIG_KEY_VERSION

const CONFIG_KEY_VERSION = 'version'

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

◆ CONFIG_SECTION_APACHE

const CONFIG_SECTION_APACHE = 'apache'

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

◆ CONFIG_SECTION_MAILPIT

const CONFIG_SECTION_MAILPIT = 'mailpit'

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

◆ CONFIG_SECTION_MARIADB

const CONFIG_SECTION_MARIADB = 'mariadb'

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

◆ CONFIG_SECTION_MEMCACHED

const CONFIG_SECTION_MEMCACHED = 'memcached'

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

◆ CONFIG_SECTION_MYSQL

const CONFIG_SECTION_MYSQL = 'mysql'

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

◆ CONFIG_SECTION_NODEJS

const CONFIG_SECTION_NODEJS = 'nodejs'

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

◆ CONFIG_SECTION_PHP

const CONFIG_SECTION_PHP = 'php'

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

◆ CONFIG_SECTION_POSTGRESQL

const CONFIG_SECTION_POSTGRESQL = 'postgresql'

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

◆ CONFIG_SECTION_XLIGHT

const CONFIG_SECTION_XLIGHT = 'xlight'

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

◆ GAUGE_OTHERS

const GAUGE_OTHERS = 7

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

◆ GAUGE_SERVICES

const GAUGE_SERVICES = 1

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


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