Bearsampp 2026.3.26
API documentation
Loading...
Searching...
No Matches
class.action.restartAllServices.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
16{
20 private $splash;
21
25 private $processed = false;
26
30 const GAUGE_PER_SERVICE = 2; // 1 for stop, 1 for start
31
38 public function __construct($args)
39 {
40 global $bearsamppCore, $bearsamppLang, $bearsamppBins, $bearsamppWinbinder;
41
42 // Count enabled services for progress bar
43 $enabledServicesCount = count($bearsamppBins->getServices());
44
45 // Start splash screen (2 operations per service: stop + start)
46 $this->splash = new Splash();
47 $this->splash->init(
49 self::GAUGE_PER_SERVICE * $enabledServicesCount + 1,
51 );
52
53 // Set handler for the splash screen window with 1000ms timeout
54 $bearsamppWinbinder->setHandler($this->splash->getWbWindow(), $this, 'processWindow', 1000);
55 $bearsamppWinbinder->mainLoop();
56 $bearsamppWinbinder->reset();
57 }
58
69 public function processWindow($window, $id, $ctrl, $param1, $param2)
70 {
71 global $bearsamppBins, $bearsamppLang, $bearsamppWinbinder;
72
73 // Only process once
74 if ($this->processed) {
75 return;
76 }
77 $this->processed = true;
78
79 // First, stop all services using ServiceHelper
80 ServiceHelper::processServices($bearsamppBins, function($serviceName, $service, $bin, $syntaxCheckCmd) use ($bearsamppLang) {
81 $name = ServiceHelper::getServiceDisplayName($bin, $service);
82
83 $this->splash->incrProgressBar();
84 $this->splash->setTextLoading(sprintf($bearsamppLang->getValue(Lang::LOADING_STOP_SERVICE), $name));
85
86 // Stop the service
88 });
89
90 // Then, start all services using ServiceHelper
91 ServiceHelper::processServices($bearsamppBins, function($serviceName, $service, $bin, $syntaxCheckCmd) use ($bearsamppLang) {
92 $name = ServiceHelper::getServiceDisplayName($bin, $service);
93
94 $this->splash->incrProgressBar();
95 $this->splash->setTextLoading(sprintf($bearsamppLang->getValue(Lang::LOADING_START_SERVICE), $name));
96
97 // Start the service
98 ServiceHelper::startService($bin, $syntaxCheckCmd, false);
99 });
100
101 // Final update
102 $this->splash->incrProgressBar();
103 $this->splash->setTextLoading($bearsamppLang->getValue(Lang::LOADING_COMPLETE));
104
105 // Close the splash screen and exit cleanly
106 $bearsamppWinbinder->destroyWindow($window);
107 $bearsamppWinbinder->reset();
108 exit(0);
109 }
110}
global $bearsamppBins
global $bearsamppLang
global $bearsamppCore
processWindow($window, $id, $ctrl, $param1, $param2)
const MENU_RESTART_SERVICES
const LOADING_COMPLETE
const LOADING_START_SERVICE
const LOADING_STOP_SERVICE
const LOADING_RESTART_SERVICES
static getServiceDisplayName($bin, $service)
static stopService($service)
static startService($bin, $syntaxCheckCmd=null, $showErrors=true)
static processServices($bearsamppBins, callable $callback)