Bearsampp 2026.9.23
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 67 of file class.action.switchVersion.php.

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

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

Here is the call graph for this function:

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

217 {
218 global $bearsamppCore, $bearsamppLang, $bearsamppBins, $bearsamppWinbinder;
219
220 if ($this->version == $this->currentVersion) {
221 $bearsamppWinbinder->messageBoxWarning(sprintf($bearsamppLang->getValue(Lang::SWITCH_VERSION_SAME_ERROR), $this->bin->getName(), $this->version), $this->boxTitle);
222 $bearsamppWinbinder->destroyWindow($window);
223 }
224
225 // scan folder
226 $this->bearsamppSplash->incrProgressBar();
227 if (!empty($this->pathsToScan)) {
228 Path::changePath(Util::getFilesToScan($this->pathsToScan));
229 }
230
231 // switch
232 $this->bearsamppSplash->incrProgressBar();
233 if ($this->bin->switchVersion($this->version, true) === false) {
234 $this->bearsamppSplash->incrProgressBar(self::GAUGE_SERVICES * count($bearsamppBins->getServices()) + self::GAUGE_OTHERS);
235 $bearsamppWinbinder->destroyWindow($window);
236 }
237
238 // stop service
239 if ($this->service != null) {
240 $binName = $this->bin->getName() == $bearsamppLang->getValue(Lang::PHP) ? $bearsamppLang->getValue(Lang::APACHE) : $this->bin->getName();
241 $this->bearsamppSplash->setTextLoading(sprintf($bearsamppLang->getValue(Lang::STOP_SERVICE_TITLE), $binName));
242 $this->bearsamppSplash->incrProgressBar();
243 $this->service->stop();
244 // Wait for SCM to stop the service
245 usleep(2000000); // 2 seconds
246 } else {
247 $this->bearsamppSplash->incrProgressBar();
248 }
249
250 // reload config
251 $this->bearsamppSplash->setTextLoading($bearsamppLang->getValue(Lang::SWITCH_VERSION_RELOAD_CONFIG));
252 $this->bearsamppSplash->incrProgressBar();
254
255 // reload bins
256 $this->bearsamppSplash->setTextLoading($bearsamppLang->getValue(Lang::SWITCH_VERSION_RELOAD_BINS));
257 $this->bearsamppSplash->incrProgressBar();
258 $bearsamppBins->reload();
259
260 // After reloading bins, get a fresh service reference from the reloaded bin.
261 // This ensures we're using the updated service instance with new configuration.
262 if ($this->service != null) {
263 // PHP is a special case: it runs under Apache's service, not its own.
264 if ($this->bin->getName() == $bearsamppBins->getPhp()->getName()) {
265 $this->service = $bearsamppBins->getApache()->getService();
266 Log::trace("Refreshed service reference from reloaded Apache bin (for PHP)");
267 } else {
268 $freshBin = $bearsamppBins->getBinByName($this->bin->getName());
269 if ($freshBin !== null) {
270 $this->service = $freshBin->getService();
271 Log::trace("Refreshed service reference from reloaded " . $this->bin->getName() . " bin");
272 }
273 }
274 }
275
276 // change port
277 if ($this->changePort) {
278 $this->bin->reload();
279 $this->bin->changePort($this->bin->getPort());
280 }
281
282 // start service
283 if ($this->service != null) {
284 $binName = $this->bin->getName() == $bearsamppLang->getValue(Lang::PHP) ? $bearsamppLang->getValue(Lang::APACHE) : $this->bin->getName();
285 $this->bearsamppSplash->setTextLoading(sprintf($bearsamppLang->getValue(Lang::START_SERVICE_TITLE), $binName));
286 $this->bearsamppSplash->incrProgressBar();
287 $this->service->start();
288 } else {
289 $this->bearsamppSplash->incrProgressBar();
290 }
291
292 $this->bearsamppSplash->incrProgressBar(self::GAUGE_SERVICES * count($bearsamppBins->getServices()) + 1);
293
294 // Update configuration file with the new version
295 Log::trace('Updating ini & menu...');
296 $this->updateConfigVersion();
297
298 // Store current registry value for comparison
299 global $bearsamppRegistry;
300 $currentRegValue = $bearsamppRegistry->getAppBinsRegKey(false);
302
304 sprintf(
305 'Starting registry adjustment for key: %s | Current value: %s',
306 $regEntry,
307 $currentRegValue
308 )
309 );
310
311 // Perform the registry update
312 $newRegValue = $bearsamppRegistry->setAppBinsRegKey($currentRegValue);
313
314 $this->bearsamppSplash->setTextLoading(
315 sprintf(
317 $regEntry
318 )
319 );
320
321 $this->bearsamppSplash->incrProgressBar(2);
323 sprintf(
324 'Registry update completed | Key: %s | New value: %s | Previous value: %s',
325 $regEntry,
326 $newRegValue,
327 $currentRegValue
328 )
329 );
330
331 $this->bearsamppSplash->setTextLoading($bearsamppLang->getValue(Lang::SWITCH_VERSION_RESET_SERVICES));
332
333 // For version switches, services are properly restarted above
334 // No additional service reset/delete is needed
335 // The service is now running with the new version
336 Log::trace('Version switch complete - service restarted with new version');
337 $this->bearsamppSplash->incrProgressBar();
338
339 // Compensate progress bar for all services (none are being reset)
340 $remainingServicesCount = count($bearsamppBins->getServices());
341 if ($remainingServicesCount > 0) {
342 $this->bearsamppSplash->incrProgressBar($remainingServicesCount);
343 }
344
345 Log::trace('Version switch process completed successfully');
346
347 Log::trace('Creating modal...');
348 $bearsamppWinbinder->messageBoxInfo(
349 sprintf($bearsamppLang->getValue(Lang::SWITCH_VERSION_OK), $this->bin->getName(), $this->version),
350 $this->boxTitle
351 );
352
353 Log::trace('Destroying splash window...');
354 $bearsamppWinbinder->destroyWindow($window);
355 }
global $bearsamppCore
const SWITCH_VERSION_RELOAD_CONFIG
const SWITCH_VERSION_RELOAD_BINS
const START_SERVICE_TITLE
const SWITCH_VERSION_REGISTRY
const SWITCH_VERSION_OK
const STOP_SERVICE_TITLE
const PHP
const APACHE
const SWITCH_VERSION_SAME_ERROR
const SWITCH_VERSION_RESET_SERVICES
static trace($data, $file=null)
static changePath($filesToScan, $rootPath=null)
const APP_BINS_REG_ENTRY
static loadConfig()
static getFilesToScan($path=null, $useCache=true, $forceRefresh=false)

References $bearsamppBins, $bearsamppCore, $bearsamppLang, Lang\APACHE, Registry\APP_BINS_REG_ENTRY, Path\changePath(), Util\getFilesToScan(), Root\loadConfig(), Lang\PHP, Lang\START_SERVICE_TITLE, Lang\STOP_SERVICE_TITLE, Lang\SWITCH_VERSION_OK, Lang\SWITCH_VERSION_REGISTRY, Lang\SWITCH_VERSION_RELOAD_BINS, Lang\SWITCH_VERSION_RELOAD_CONFIG, Lang\SWITCH_VERSION_RESET_SERVICES, Lang\SWITCH_VERSION_SAME_ERROR, Log\trace(), and updateConfigVersion().

Here is the call graph for this function:

◆ updateConfigVersion()

updateConfigVersion ( )
private

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

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

361 : void
362 {
363 $bearsamppConfig = new Config();
364 $configSection = '';
365 $version = $this->version; // Ensure version is available in scope
366
367 // Determine the correct configuration section based on binary type
368 if ($this->bin->getName() == $GLOBALS['bearsamppBins']->getApache()->getName()) {
369 $configSection = self::CONFIG_SECTION_APACHE;
370 Log::trace(sprintf('Switch %s version to %s', $configSection, $version));
371 } elseif ($this->bin->getName() == $GLOBALS['bearsamppBins']->getPhp()->getName()) {
372 $configSection = self::CONFIG_SECTION_PHP;
373 Log::trace(sprintf('Switch %s version to %s', $configSection, $version));
374 } elseif ($this->bin->getName() == $GLOBALS['bearsamppBins']->getMysql()->getName()) {
375 $configSection = self::CONFIG_SECTION_MYSQL;
376 Log::trace(sprintf('Switch %s version to %s', $configSection, $version));
377 } elseif ($this->bin->getName() == $GLOBALS['bearsamppBins']->getMariadb()->getName()) {
378 $configSection = self::CONFIG_SECTION_MARIADB;
379 Log::trace(sprintf('Switch %s version to %s', $configSection, $version));
380 } elseif ($this->bin->getName() == $GLOBALS['bearsamppBins']->getPostgresql()->getName()) {
381 $configSection = self::CONFIG_SECTION_POSTGRESQL;
382 Log::trace(sprintf('Switch %s version to %s', $configSection, $version));
383 } elseif ($this->bin->getName() == $GLOBALS['bearsamppBins']->getNodejs()->getName()) {
384 $configSection = self::CONFIG_SECTION_NODEJS;
385 Log::trace(sprintf('Switch %s version to %s', $configSection, $version));
386 } elseif ($this->bin->getName() == $GLOBALS['bearsamppBins']->getMemcached()->getName()) {
387 $configSection = self::CONFIG_SECTION_MEMCACHED;
388 Log::trace(sprintf('Switch %s version to %s', $configSection, $version));
389 } elseif ($this->bin->getName() == $GLOBALS['bearsamppBins']->getMailpit()->getName()) {
390 $configSection = self::CONFIG_SECTION_MAILPIT;
391 Log::trace(sprintf('Switch %s version to %s', $configSection, $version));
392 } elseif ($this->bin->getName() == $GLOBALS['bearsamppBins']->getXlight()->getName()) {
393 $configSection = self::CONFIG_SECTION_XLIGHT;
394 Log::trace(sprintf('Switch %s version to %s', $configSection, $version));
395 }
396
397 // Update the configuration if a valid section was found
398 if (!empty($configSection)) {
399 Log::trace('Updating .ini file...');
400 $bearsamppConfig->replace($configSection, self::CONFIG_KEY_VERSION, $version);
401
402 // Update tray menu display if TrayMenu class is available
403 Log::trace('Updating TrayMenu...');
404 if (class_exists('TrayMenu')) {
405 $trayMenu = TrayMenu::getInstance();
406 if (method_exists($trayMenu, 'updateSectionVersion')) {
407 $trayMenu->updateSectionVersion(
408 strtoupper($configSection),
410 );
411 }
412 }
413 }
414 Log::trace('Returning to parent call');
415 }
$GLOBALS['_PEAR_default_error_mode']
Definition PEAR.php:46
global $bearsamppConfig
Definition homepage.php:46

References $bearsamppConfig, $GLOBALS, $version, and Log\trace().

Referenced by processWindow().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ $bearsamppSplash

$bearsamppSplash
private

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

◆ $bin

$bin
private

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

◆ $boxTitle

$boxTitle
private

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

◆ $changePort

$changePort
private

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

◆ $currentVersion

$currentVersion
private

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

◆ $pathsToScan

$pathsToScan = []
private

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

◆ $service

$service
private

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

◆ $version

$version
private

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

Referenced by updateConfigVersion().

◆ CONFIG_KEY_VERSION

const CONFIG_KEY_VERSION = 'version'

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

◆ CONFIG_SECTION_APACHE

const CONFIG_SECTION_APACHE = 'apache'

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

◆ CONFIG_SECTION_MAILPIT

const CONFIG_SECTION_MAILPIT = 'mailpit'

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

◆ CONFIG_SECTION_MARIADB

const CONFIG_SECTION_MARIADB = 'mariadb'

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

◆ CONFIG_SECTION_MEMCACHED

const CONFIG_SECTION_MEMCACHED = 'memcached'

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

◆ CONFIG_SECTION_MYSQL

const CONFIG_SECTION_MYSQL = 'mysql'

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

◆ CONFIG_SECTION_NODEJS

const CONFIG_SECTION_NODEJS = 'nodejs'

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

◆ CONFIG_SECTION_PHP

const CONFIG_SECTION_PHP = 'php'

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

◆ CONFIG_SECTION_POSTGRESQL

const CONFIG_SECTION_POSTGRESQL = 'postgresql'

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

◆ CONFIG_SECTION_XLIGHT

const CONFIG_SECTION_XLIGHT = 'xlight'

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

◆ GAUGE_OTHERS

const GAUGE_OTHERS = 7

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

◆ GAUGE_SERVICES

const GAUGE_SERVICES = 1

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


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