Bearsampp 2026.7.28
Loading...
Searching...
No Matches
ActionReload Class Reference

Public Member Functions

 __construct ($args)

Detailed Description

Class ActionReload

This class handles the reloading of various configurations and settings for the Bearsampp application. It performs operations such as refreshing the hostname, updating startup settings, checking and updating the browser configuration, processing configuration files, and rebuilding certain cached contents.

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

Constructor & Destructor Documentation

◆ __construct()

__construct ( $args)

Constructs an ActionReload object and performs various refresh operations.

Parameters
array$argsThe arguments passed to the constructor.

@global Root $bearsamppRoot The root object of the Bearsampp application. @global Core $bearsamppCore The core object of the Bearsampp application. @global Config $bearsamppConfig The configuration object of the Bearsampp application. @global Bins $bearsamppBins The bins object containing various binaries used by the Bearsampp application. @global Apps $bearsamppApps The apps object containing various applications used by the Bearsampp application. @global Homepage $bearsamppHomepage The homepage object for managing homepage-related settings and content.

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

32 {
34
35 // If the executable file exists, return early.
36 if (file_exists($bearsamppCore->getExec())) {
37 return;
38 }
39
40 // Start loading process
42
43 // Capture which database services are currently running so we can restart them once
44 // the reload has finished. A running database server keeps executing the binary it was
45 // launched with, so it keeps reporting the old version to clients such as phpMyAdmin
46 // until it is restarted from the updated 'current' symlink. Only the database services
47 // are handled here: the rest of the reload already refreshes the other modules, and
48 // restarting every service needlessly disrupts them (and makes the tray flash a window
49 // per service).
50 $dbServiceNames = array(
54 );
55
56 $runningServices = array();
57 $stoppedServices = array();
58 $services = $bearsamppBins->getServices();
59 foreach ($dbServiceNames as $serviceName) {
60 if (isset($services[$serviceName]) && $services[$serviceName] != null && $services[$serviceName]->isRunning()) {
61 $runningServices[] = $serviceName;
62 Log::info('Stopping ' . $serviceName . ' before reload');
63 if ($services[$serviceName]->stop()) {
64 $stoppedServices[] = $serviceName;
65 } else {
66 Log::error('Failed to stop ' . $serviceName . ' before reload');
67 }
68 }
69 }
70
71 try {
72 // Scan and update paths in bin configuration files (replaces path placeholders
73 // such as ~BEARSAMPP_LIN_PATH~ for the newly selected version, like switchVersion does)
74 $pathsToScan = array();
75
76 // MySQL
78 if ($folderList === false) {
79 Log::error('Failed to scan MySQL module folder list for path updates');
80 $folderList = array();
81 }
82 foreach ($folderList as $folder) {
83 $pathsToScan[] = array(
84 'path' => Path::getModuleRootPath($bearsamppBins->getMysql()) . '/' . $folder,
85 'includes' => array('my.ini'),
86 'recursive' => false
87 );
88 }
89
90 // MariaDB
92 if ($folderList === false) {
93 Log::error('Failed to scan MariaDB module folder list for path updates');
94 $folderList = array();
95 }
96 foreach ($folderList as $folder) {
97 $pathsToScan[] = array(
98 'path' => Path::getModuleRootPath($bearsamppBins->getMariadb()) . '/' . $folder,
99 'includes' => array('my.ini'),
100 'recursive' => false
101 );
102 }
103
104 // Update paths in scanned files
105 if (!empty($pathsToScan)) {
107 }
108
109 // Reload bins and apps to recreate symlinks if needed
110 $bearsamppBins->reload();
111 $bearsamppApps->reload();
112
113 // Refresh application configs (ports/credentials) against the reloaded bins
114 $bearsamppApps->getPhpmyadmin()->update();
115 $bearsamppApps->getPhppgadmin()->update();
116
117 // Refresh hostname in the configuration
118 $bearsamppConfig->replace(Config::CFG_HOSTNAME, gethostname());
119
120 // Refresh launch startup setting in the configuration
122
123 // Check and update the browser setting in the configuration
124 $currentBrowser = $bearsamppConfig->getBrowser();
125 if (empty($currentBrowser) || !file_exists($currentBrowser)) {
127 }
128
129 // Process and update the bearsampp.ini file
131
132 // Process and update the PowerShell configuration
134
135 // Refresh PEAR version cache file
136 $bearsamppBins->getPhp()->getPearVersion();
137
138 // Rebuild alias homepage content
139 $bearsamppHomepage->refreshAliasContent();
140
141 // Rebuild _commons.js content
142 $bearsamppHomepage->refreshCommonsJsContent();
143 } finally {
144 // Restart the services that were successfully stopped. Because the bins have
145 // been reloaded and the 'current' symlink now points to the selected version, the
146 // service starts from the new binary and reports the new version to clients such
147 // as phpMyAdmin. Fresh service references are taken from the reloaded bins.
148 $failedServices = array();
149 if (!empty($stoppedServices)) {
150 $services = $bearsamppBins->getServices();
151 foreach ($stoppedServices as $serviceName) {
152 if (isset($services[$serviceName]) && $services[$serviceName] != null) {
153 Log::info('Restarting ' . $serviceName . ' after reload');
154 if (!$services[$serviceName]->start()) {
155 Log::error('Failed to restart ' . $serviceName . ' after reload');
156 $failedServices[] = $serviceName;
157 }
158 }
159 }
160 }
161
162 // Write reload status file for UI to poll and display results
163 $reloadStatusFile = Path::getLogsPath() . '/reload-status.json';
164 $reloadStatus = array(
165 'timestamp' => time(),
166 'stoppedServices' => $stoppedServices,
167 'failedServices' => $failedServices,
168 'success' => empty($failedServices)
169 );
170
171 // Atomic write: write to temp file, then rename to final path to prevent partial reads
172 $reloadStatusTmpFile = $reloadStatusFile . '.tmp';
173 file_put_contents($reloadStatusTmpFile, json_encode($reloadStatus, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), LOCK_EX);
174 rename($reloadStatusTmpFile, $reloadStatusFile);
175
176 // Stop loading process
178 }
179 }
global $bearsamppBins
global $bearsamppRoot
global $bearsamppCore
const SERVICE_NAME
const CFG_HOSTNAME
const DISABLED
const CFG_BROWSER
const ENABLED
const CFG_LAUNCH_STARTUP
static info($data, $file=null)
static error($data, $file=null)
static getLogsPath($aetrayPath=false)
static changePath($filesToScan, $rootPath=null)
static getModuleRootPath($module)
static getIniFilePath($aetrayPath=false)
static process()
static isLaunchStartup()
static utf8ToCp1252($data)
static getFolderList($path)
static startLoading()
static getFilesToScan($path=null, $useCache=true, $forceRefresh=false)
static stopLoading()
static getDefaultBrowser()
global $bearsamppConfig
Definition homepage.php:41
global $bearsamppHomepage
Definition homepage.php:41

References $bearsamppBins, $bearsamppConfig, $bearsamppCore, $bearsamppHomepage, $bearsamppRoot, Config\CFG_BROWSER, Config\CFG_HOSTNAME, Config\CFG_LAUNCH_STARTUP, Path\changePath(), Config\DISABLED, Config\ENABLED, Log\error(), Win32Native\getDefaultBrowser(), Util\getFilesToScan(), Util\getFolderList(), Path\getIniFilePath(), Path\getLogsPath(), Path\getModuleRootPath(), Log\info(), Util\isLaunchStartup(), TplApp\process(), TplPowerShell\process(), BinMariadb\SERVICE_NAME, BinMysql\SERVICE_NAME, BinPostgresql\SERVICE_NAME, Util\startLoading(), Util\stopLoading(), and Util\utf8ToCp1252().

Here is the call graph for this function:

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