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

Public Member Functions

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

Data Fields

const GAUGE_OTHERS = 19
 
const GAUGE_SERVICES = 5
 

Private Member Functions

 changePath ()
 
 checkBinsRegKey ()
 
 checkBrowser ()
 
 checkLaunchStartup ()
 
 checkPath ()
 
 checkPathRegKey ()
 
 checkSystemPathRegKey ()
 
 cleanOldBehaviors ()
 
 cleanTmpFolders ()
 
 createSslCrts ()
 
 installServices ()
 
 killOldInstances ()
 
 refreshAliases ()
 
 refreshGitRepos ()
 
 refreshHostname ()
 
 refreshVhosts ()
 
 rotationLogs ()
 
 savePath ()
 
 scanFolders ()
 
 sysInfos ()
 
 updateConfig ()
 
 writeLog ($log)
 

Private Attributes

 $error
 
 $filesToScan
 
 $restart
 
 $rootPath
 
 $splash
 
 $startTime
 

Detailed Description

Class ActionStartup Handles the startup process of the Bearsampp application, including initializing services, cleaning temporary files, refreshing configurations, and more.

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

Constructor & Destructor Documentation

◆ __construct()

ActionStartup::__construct ( $args)

ActionStartup constructor. Initializes the startup process, including the splash screen and various configurations.

Parameters
array$argsCommand line arguments.

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

35 {
36 global $bearsamppRoot, $bearsamppCore, $bearsamppLang, $bearsamppBins, $bearsamppWinbinder;
37 $this->writeLog( 'Starting ' . APP_TITLE );
38
39 // Init
40 $this->splash = new Splash();
41 $this->restart = false;
42 $this->startTime = Util::getMicrotime();
43 $this->error = '';
44
45 $this->rootPath = $bearsamppRoot->getRootPath();
46 $this->filesToScan = array();
47
48 $gauge = self::GAUGE_SERVICES * count( $bearsamppBins->getServices() );
49 $gauge += self::GAUGE_OTHERS + 1;
50
51 // Start splash screen
52 $this->splash->init(
53 $bearsamppLang->getValue( Lang::STARTUP ),
54 $gauge,
55 sprintf( $bearsamppLang->getValue( Lang::STARTUP_STARTING_TEXT ), APP_TITLE . ' ' . $bearsamppCore->getAppVersion() )
56 );
57
58 $bearsamppWinbinder->setHandler( $this->splash->getWbWindow(), $this, 'processWindow', 1000 );
59 $bearsamppWinbinder->mainLoop();
60 $bearsamppWinbinder->reset();
61 }
global $bearsamppBins
global $bearsamppLang
global $bearsamppRoot
global $bearsamppCore
const STARTUP
const STARTUP_STARTING_TEXT
static getMicrotime()
const APP_TITLE
Definition root.php:12

References $bearsamppBins, $bearsamppCore, $bearsamppLang, $bearsamppRoot, APP_TITLE, Util\getMicrotime(), Lang\STARTUP, Lang\STARTUP_STARTING_TEXT, and writeLog().

Member Function Documentation

◆ changePath()

ActionStartup::changePath ( )
private

Changes the application path and logs the number of files and occurrences changed.

Definition at line 460 of file class.action.startup.php.

461 {
462 global $bearsamppLang;
463
464 $this->splash->setTextLoading( sprintf( $bearsamppLang->getValue( Lang::STARTUP_CHANGE_PATH_TEXT ), $this->rootPath ) );
465 $this->splash->incrProgressBar();
466
467 $result = Util::changePath( $this->filesToScan, $this->rootPath );
468 $this->writeLog( 'Nb files changed: ' . $result['countChangedFiles'] );
469 $this->writeLog( 'Nb occurences changed: ' . $result['countChangedOcc'] );
470 }
$result
const STARTUP_CHANGE_PATH_TEXT
static changePath($filesToScan, $rootPath=null)

References $bearsamppLang, $result, Util\changePath(), Lang\STARTUP_CHANGE_PATH_TEXT, and writeLog().

Referenced by processWindow().

+ Here is the caller graph for this function:

◆ checkBinsRegKey()

ActionStartup::checkBinsRegKey ( )
private

Checks and updates the application bins registry key. If the current registry key does not match the generated key, it updates the registry key. Logs the current and generated registry keys. Sets an error message if the registry key update fails. Sets a restart flag if the registry key is updated.

Definition at line 519 of file class.action.startup.php.

520 {
521 global $bearsamppLang, $bearsamppRegistry;
522
523 $this->splash->setTextLoading( sprintf( $bearsamppLang->getValue( Lang::STARTUP_REGISTRY_TEXT ), Registry::APP_BINS_REG_ENTRY ) );
524 $this->splash->incrProgressBar();
525
526 $currentAppBinsRegKey = Util::getAppBinsRegKey();
527 $genAppBinsRegKey = Util::getAppBinsRegKey( false );
528 $this->writeLog( 'Current app bins reg key: ' . $currentAppBinsRegKey );
529 $this->writeLog( 'Gen app bins reg key: ' . $genAppBinsRegKey );
530 if ( $currentAppBinsRegKey != $genAppBinsRegKey ) {
531 if ( !Util::setAppBinsRegKey( $genAppBinsRegKey ) ) {
532 if ( !empty( $this->error ) ) {
533 $this->error .= PHP_EOL . PHP_EOL;
534 }
536 $this->error .= PHP_EOL . $bearsamppRegistry->getLatestError();
537 }
538 else {
539 $this->writeLog( 'Need restart: checkBinsRegKey' );
540 $this->restart = true;
541 }
542 }
543 }
const STARTUP_REGISTRY_ERROR_TEXT
const STARTUP_REGISTRY_TEXT
const APP_BINS_REG_ENTRY
static setAppBinsRegKey($value)
static getAppBinsRegKey($fromRegistry=true)

References $bearsamppLang, Registry\APP_BINS_REG_ENTRY, Util\getAppBinsRegKey(), Util\setAppBinsRegKey(), Lang\STARTUP_REGISTRY_ERROR_TEXT, Lang\STARTUP_REGISTRY_TEXT, and writeLog().

Referenced by processWindow().

+ Here is the caller graph for this function:

◆ checkBrowser()

ActionStartup::checkBrowser ( )
private

Checks and sets the default browser configuration.

Definition at line 374 of file class.action.startup.php.

375 {
377
378 $this->splash->setTextLoading( $bearsamppLang->getValue( Lang::STARTUP_CHECK_BROWSER_TEXT ) );
379 $this->splash->incrProgressBar();
380 $this->writeLog( 'Check browser' );
381
382 $currentBrowser = $bearsamppConfig->getBrowser();
383 if ( empty( $currentBrowser ) || !file_exists( $currentBrowser ) ) {
385 }
386 }
const CFG_BROWSER
const STARTUP_CHECK_BROWSER_TEXT
static getDefaultBrowser()
Definition class.vbs.php:80
global $bearsamppConfig
Definition homepage.php:26

References $bearsamppConfig, $bearsamppLang, Config\CFG_BROWSER, Vbs\getDefaultBrowser(), Lang\STARTUP_CHECK_BROWSER_TEXT, and writeLog().

Referenced by processWindow().

+ Here is the caller graph for this function:

◆ checkLaunchStartup()

ActionStartup::checkLaunchStartup ( )
private

Checks and sets the launch startup configuration.

Definition at line 357 of file class.action.startup.php.

358 {
359 global $bearsamppConfig;
360
361 $this->writeLog( 'Check launch startup' );
362
363 if ( $bearsamppConfig->isLaunchStartup() ) {
365 }
366 else {
368 }
369 }
static enableLaunchStartup()
static disableLaunchStartup()

References $bearsamppConfig, Util\disableLaunchStartup(), Util\enableLaunchStartup(), and writeLog().

Referenced by processWindow().

+ Here is the caller graph for this function:

◆ checkPath()

ActionStartup::checkPath ( )
private

Checks the application path and logs the last path content.

Definition at line 433 of file class.action.startup.php.

434 {
436
437 $this->splash->setTextLoading( $bearsamppLang->getValue( Lang::STARTUP_CHECK_PATH_TEXT ) );
438 $this->splash->incrProgressBar();
439
440 $this->writeLog( 'Last path: ' . $bearsamppCore->getLastPathContent() );
441 }
const STARTUP_CHECK_PATH_TEXT

References $bearsamppCore, $bearsamppLang, Lang\STARTUP_CHECK_PATH_TEXT, and writeLog().

Referenced by processWindow().

+ Here is the caller graph for this function:

◆ checkPathRegKey()

ActionStartup::checkPathRegKey ( )
private

Checks and updates the application path registry key.

Definition at line 486 of file class.action.startup.php.

487 {
488 global $bearsamppRoot, $bearsamppLang, $bearsamppRegistry;
489
490 $this->splash->setTextLoading( sprintf( $bearsamppLang->getValue( Lang::STARTUP_REGISTRY_TEXT ), Registry::APP_PATH_REG_ENTRY ) );
491 $this->splash->incrProgressBar();
492
493 $currentAppPathRegKey = Util::getAppPathRegKey();
494 $genAppPathRegKey = Util::formatWindowsPath( $bearsamppRoot->getRootPath() );
495 $this->writeLog( 'Current app path reg key: ' . $currentAppPathRegKey );
496 $this->writeLog( 'Gen app path reg key: ' . $genAppPathRegKey );
497 if ( $currentAppPathRegKey != $genAppPathRegKey ) {
498 if ( !Util::setAppPathRegKey( $genAppPathRegKey ) ) {
499 if ( !empty( $this->error ) ) {
500 $this->error .= PHP_EOL . PHP_EOL;
501 }
503 $this->error .= PHP_EOL . $bearsamppRegistry->getLatestError();
504 }
505 else {
506 $this->writeLog( 'Need restart: checkPathRegKey' );
507 $this->restart = true;
508 }
509 }
510 }
const APP_PATH_REG_ENTRY
static setAppPathRegKey($value)
static getAppPathRegKey()
static formatWindowsPath($path)

References $bearsamppLang, $bearsamppRoot, Registry\APP_PATH_REG_ENTRY, Util\formatWindowsPath(), Util\getAppPathRegKey(), Util\setAppPathRegKey(), Lang\STARTUP_REGISTRY_ERROR_TEXT, Lang\STARTUP_REGISTRY_TEXT, and writeLog().

Referenced by processWindow().

+ Here is the caller graph for this function:

◆ checkSystemPathRegKey()

ActionStartup::checkSystemPathRegKey ( )
private

Checks and updates the system PATH registry key. Ensures the application bins registry entry is at the beginning of the system PATH. Logs the current and new system PATH. Sets an error message if the system PATH update fails. Sets a restart flag if the system PATH is updated.

Definition at line 552 of file class.action.startup.php.

553 {
554 global $bearsamppLang, $bearsamppRegistry;
555
556 $this->splash->setTextLoading( sprintf( $bearsamppLang->getValue( Lang::STARTUP_REGISTRY_TEXT ), Registry::SYSPATH_REG_ENTRY ) );
557 $this->splash->incrProgressBar();
558
559 $currentSysPathRegKey = Util::getSysPathRegKey();
560 $this->writeLog( 'Current system PATH: ' . $currentSysPathRegKey );
561
562 $newSysPathRegKey = str_replace( '%' . Registry::APP_BINS_REG_ENTRY . '%;', '', $currentSysPathRegKey );
563 $newSysPathRegKey = str_replace( '%' . Registry::APP_BINS_REG_ENTRY . '%', '', $newSysPathRegKey );
564 $newSysPathRegKey = '%' . Registry::APP_BINS_REG_ENTRY . '%;' . $newSysPathRegKey;
565 $this->writeLog( 'New system PATH: ' . $newSysPathRegKey );
566
567 if ( $currentSysPathRegKey != $newSysPathRegKey ) {
568 if ( !Util::setSysPathRegKey( $newSysPathRegKey ) ) {
569 if ( !empty( $this->error ) ) {
570 $this->error .= PHP_EOL . PHP_EOL;
571 }
573 $this->error .= PHP_EOL . $bearsamppRegistry->getLatestError();
574 }
575 else {
576 $this->writeLog( 'Need restart: checkSystemPathRegKey' );
577 $this->restart = true;
578 }
579 }
580 else {
581 $this->writeLog( 'Refresh system PATH: ' . $currentSysPathRegKey );
582 Util::setSysPathRegKey( str_replace( '%' . Registry::APP_BINS_REG_ENTRY . '%', '', $currentSysPathRegKey ) );
583 Util::setSysPathRegKey( $currentSysPathRegKey );
584 }
585 }
const SYSPATH_REG_ENTRY
static setSysPathRegKey($value)
static getSysPathRegKey()

References $bearsamppLang, Registry\APP_BINS_REG_ENTRY, Util\getSysPathRegKey(), Util\setSysPathRegKey(), Lang\STARTUP_REGISTRY_ERROR_TEXT, Lang\STARTUP_REGISTRY_TEXT, Registry\SYSPATH_REG_ENTRY, and writeLog().

Referenced by processWindow().

+ Here is the caller graph for this function:

◆ cleanOldBehaviors()

ActionStartup::cleanOldBehaviors ( )
private

Cleans old behaviors by removing outdated registry entries.

Definition at line 288 of file class.action.startup.php.

289 {
290 global $bearsamppLang, $bearsamppRegistry;
291
292 $this->writeLog( 'Clean old behaviors' );
293
294 $this->splash->setTextLoading( $bearsamppLang->getValue( Lang::STARTUP_CLEAN_OLD_BEHAVIORS_TEXT ) );
295 $this->splash->incrProgressBar();
296
297 // App >= 1.0.13
298 $bearsamppRegistry->deleteValue(
300 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run',
302 );
303 }
const STARTUP_CLEAN_OLD_BEHAVIORS_TEXT
const HKEY_LOCAL_MACHINE

References $bearsamppLang, APP_TITLE, Registry\HKEY_LOCAL_MACHINE, Lang\STARTUP_CLEAN_OLD_BEHAVIORS_TEXT, and writeLog().

Referenced by processWindow().

+ Here is the caller graph for this function:

◆ cleanTmpFolders()

ActionStartup::cleanTmpFolders ( )
private

Cleans temporary folders by removing unnecessary files.

Definition at line 273 of file class.action.startup.php.

274 {
276
277 $this->splash->setTextLoading( $bearsamppLang->getValue( Lang::STARTUP_CLEAN_TMP_TEXT ) );
278 $this->splash->incrProgressBar();
279
280 $this->writeLog( 'Clear tmp folders' );
281 Util::clearFolder( $bearsamppRoot->getTmpPath(), array('cachegrind', 'composer', 'openssl', 'mailhog', 'mailpit', 'xlight', 'npm-cache', 'pip', 'yarn', '.gitignore') );
282 Util::clearFolder( $bearsamppCore->getTmpPath(), array('.gitignore') );
283 }
const STARTUP_CLEAN_TMP_TEXT
static clearFolder($path, $exclude=array())

References $bearsamppCore, $bearsamppLang, $bearsamppRoot, Util\clearFolder(), Lang\STARTUP_CLEAN_TMP_TEXT, and writeLog().

Referenced by processWindow().

+ Here is the caller graph for this function:

◆ createSslCrts()

ActionStartup::createSslCrts ( )
private

Creates SSL certificates if they do not already exist. Logs the creation process.

Definition at line 608 of file class.action.startup.php.

609 {
610 global $bearsamppLang, $bearsamppOpenSsl;
611
612 $this->splash->incrProgressBar();
613 if ( !$bearsamppOpenSsl->existsCrt( 'localhost' ) ) {
614 $this->splash->setTextLoading( sprintf( $bearsamppLang->getValue( Lang::STARTUP_GEN_SSL_CRT_TEXT ), 'localhost' ) );
615 $bearsamppOpenSsl->createCrt( 'localhost' );
616 }
617 }
const STARTUP_GEN_SSL_CRT_TEXT

References $bearsamppLang, and Lang\STARTUP_GEN_SSL_CRT_TEXT.

Referenced by processWindow().

+ Here is the caller graph for this function:

◆ installServices()

ActionStartup::installServices ( )
private

Installs and starts services for the application. Checks if services are already installed and updates them if necessary. Logs the installation process and any errors encountered.

Definition at line 624 of file class.action.startup.php.

625 {
627
628 if ( !$this->restart ) {
629
630 foreach ( $bearsamppBins->getServices() as $sName => $service ) {
631 $serviceError = '';
632 $serviceRestart = false;
633 $serviceAlreadyInstalled = false;
634 $serviceToRemove = false;
635 $startServiceTime = Util::getMicrotime();
636
637 $syntaxCheckCmd = null;
638 $bin = null;
639 $port = 0;
640 if ( $sName == BinMailhog::SERVICE_NAME ) {
641 $bin = $bearsamppBins->getMailhog();
642 $port = $bearsamppBins->getMailhog()->getSmtpPort();
643 }
644 elseif ( $sName == BinMailpit::SERVICE_NAME ) {
645 $bin = $bearsamppBins->getMailpit();
646 $port = $bearsamppBins->getMailpit()->getSmtpPort();
647 }
648 elseif ( $sName == BinMemcached::SERVICE_NAME ) {
649 $bin = $bearsamppBins->getMemcached();
650 $port = $bearsamppBins->getMemcached()->getPort();
651 }
652 elseif ( $sName == BinApache::SERVICE_NAME ) {
653 $bin = $bearsamppBins->getApache();
654 $port = $bearsamppBins->getApache()->getPort();
655 $syntaxCheckCmd = BinApache::CMD_SYNTAX_CHECK;
656 }
657 elseif ( $sName == BinMysql::SERVICE_NAME ) {
658 $bin = $bearsamppBins->getMysql();
659 $port = $bearsamppBins->getMysql()->getPort();
660 $syntaxCheckCmd = BinMysql::CMD_SYNTAX_CHECK;
661 }
662 elseif ( $sName == BinMariadb::SERVICE_NAME ) {
663 $bin = $bearsamppBins->getMariadb();
664 $port = $bearsamppBins->getMariadb()->getPort();
665 $syntaxCheckCmd = BinMariadb::CMD_SYNTAX_CHECK;
666 }
667 elseif ( $sName == BinPostgresql::SERVICE_NAME ) {
668 $bin = $bearsamppBins->getPostgresql();
669 $port = $bearsamppBins->getPostgresql()->getPort();
670 }
671 elseif ( $sName == BinFilezilla::SERVICE_NAME ) {
672 $bin = $bearsamppBins->getFilezilla();
673 $port = $bearsamppBins->getFilezilla()->getPort();
674 }
675 elseif ( $sName == BinXlight::SERVICE_NAME ) {
676 $bin = $bearsamppBins->getXlight();
677 $port = $bearsamppBins->getXlight()->getPort();
678 }
679
680 $name = $bin->getName() . ' ' . $bin->getVersion() . ' (' . $service->getName() . ')';
681
682 $this->splash->incrProgressBar();
683 $this->splash->setTextLoading( sprintf( $bearsamppLang->getValue( Lang::STARTUP_CHECK_SERVICE_TEXT ), $name ) );
684 $serviceInfos = $service->infos();
685 if ( $serviceInfos !== false ) {
686 $serviceAlreadyInstalled = true;
687 $this->writeLog( $name . ' service already installed' );
688 foreach ( $serviceInfos as $key => $value ) {
689 $this->writeLog( '-> ' . $key . ': ' . $value );
690 }
691 $serviceGenPathName = trim( str_replace( '"', '', $service->getBinPath() . ($service->getParams() ? ' ' . $service->getParams() : '') ) );
692 $serviceVbsPathName = trim( str_replace( '"', '', $serviceInfos[Win32Service::VBS_PATH_NAME] ) );
693 if ( $serviceGenPathName != $serviceVbsPathName ) {
694 $serviceToRemove = true;
695 $this->writeLog( $name . ' service has to be removed' );
696 $this->writeLog( '-> serviceGenPathName: ' . $serviceGenPathName );
697 $this->writeLog( '-> serviceVbsPathName: ' . $serviceVbsPathName );
698 }
699 }
700
701 $this->splash->incrProgressBar();
702 if ( $serviceToRemove && !$service->delete() ) {
703 $serviceRestart = true;
704 }
705
706 if ( !$serviceRestart ) {
707 $isPortInUse = Util::isPortInUse( $port );
708 if ( $isPortInUse === false ) {
709 $this->splash->incrProgressBar();
710 if ( !$serviceAlreadyInstalled && !$serviceToRemove ) {
711 $this->splash->setTextLoading( sprintf( $bearsamppLang->getValue( Lang::STARTUP_INSTALL_SERVICE_TEXT ), $name ) );
712 if ( !$service->create() ) {
713 $serviceError .= sprintf( $bearsamppLang->getValue( Lang::STARTUP_SERVICE_CREATE_ERROR ), $service->getError() );
714 }
715 }
716
717 $this->splash->incrProgressBar();
718 $this->splash->setTextLoading( sprintf( $bearsamppLang->getValue( Lang::STARTUP_START_SERVICE_TEXT ), $name ) );
719 if ( !$service->start() ) {
720 if ( !empty( $serviceError ) ) {
721 $serviceError .= PHP_EOL;
722 }
723 $serviceError .= sprintf( $bearsamppLang->getValue( Lang::STARTUP_SERVICE_START_ERROR ), $service->getError() );
724 if ( !empty( $syntaxCheckCmd ) ) {
725 $cmdSyntaxCheck = $bin->getCmdLineOutput( $syntaxCheckCmd );
726 if ( !$cmdSyntaxCheck['syntaxOk'] ) {
727 $serviceError .= PHP_EOL . sprintf( $bearsamppLang->getValue( Lang::STARTUP_SERVICE_SYNTAX_ERROR ), $cmdSyntaxCheck['content'] );
728 }
729 }
730 }
731 $this->splash->incrProgressBar();
732 }
733 else {
734 if ( !empty( $serviceError ) ) {
735 $serviceError .= PHP_EOL;
736 }
737 $serviceError .= sprintf( $bearsamppLang->getValue( Lang::STARTUP_SERVICE_PORT_ERROR ), $port, $isPortInUse );
738 $this->splash->incrProgressBar( 3 );
739 }
740 }
741 else {
742 $this->writeLog( 'Need restart: installService ' . $bin->getName() );
743 $this->restart = true;
744 $this->splash->incrProgressBar( 3 );
745 }
746
747 if ( !empty( $serviceError ) ) {
748 if ( !empty( $this->error ) ) {
749 $this->error .= PHP_EOL . PHP_EOL;
750 }
751 $this->error .= sprintf( $bearsamppLang->getValue( Lang::STARTUP_SERVICE_ERROR ), $name ) . PHP_EOL . $serviceError;
752 }
753 else {
754 $this->writeLog( $name . ' service installed in ' . round( Util::getMicrotime() - $startServiceTime, 3 ) . 's' );
755 }
756 }
757 }
758 else {
759 $this->splash->incrProgressBar( self::GAUGE_SERVICES * count( $bearsamppBins->getServices() ) );
760 }
761 }
$port
const CMD_SYNTAX_CHECK
const CMD_SYNTAX_CHECK
const SERVICE_NAME
const STARTUP_INSTALL_SERVICE_TEXT
const STARTUP_CHECK_SERVICE_TEXT
const STARTUP_SERVICE_CREATE_ERROR
const STARTUP_SERVICE_ERROR
const STARTUP_SERVICE_SYNTAX_ERROR
const STARTUP_SERVICE_PORT_ERROR
const STARTUP_START_SERVICE_TEXT
const STARTUP_SERVICE_START_ERROR
static isPortInUse($port)

References $bearsamppBins, $bearsamppLang, $bearsamppRoot, $port, BinApache\CMD_SYNTAX_CHECK, BinMariadb\CMD_SYNTAX_CHECK, BinMysql\CMD_SYNTAX_CHECK, Util\getMicrotime(), Util\isPortInUse(), BinApache\SERVICE_NAME, BinFilezilla\SERVICE_NAME, BinMailhog\SERVICE_NAME, BinMailpit\SERVICE_NAME, BinMariadb\SERVICE_NAME, BinMemcached\SERVICE_NAME, BinMysql\SERVICE_NAME, BinPostgresql\SERVICE_NAME, BinXlight\SERVICE_NAME, Lang\STARTUP_CHECK_SERVICE_TEXT, Lang\STARTUP_INSTALL_SERVICE_TEXT, Lang\STARTUP_SERVICE_CREATE_ERROR, Lang\STARTUP_SERVICE_ERROR, Lang\STARTUP_SERVICE_PORT_ERROR, Lang\STARTUP_SERVICE_START_ERROR, Lang\STARTUP_SERVICE_SYNTAX_ERROR, Lang\STARTUP_START_SERVICE_TEXT, Win32Service\VBS_PATH_NAME, and writeLog().

Referenced by processWindow().

+ Here is the caller graph for this function:

◆ killOldInstances()

ActionStartup::killOldInstances ( )
private

Kills old instances of Bearsampp processes.

Definition at line 308 of file class.action.startup.php.

309 {
310 global $bearsamppLang;
311
312 $this->splash->setTextLoading( $bearsamppLang->getValue( Lang::STARTUP_KILL_OLD_PROCS_TEXT ) );
313 $this->splash->incrProgressBar();
314
315 // Stop services
316 /*foreach ($bearsamppBins->getServices() as $sName => $service) {
317 $serviceInfos = $service->infos();
318 if ($serviceInfos === false) {
319 continue;
320 }
321 $service->stop();
322 }*/
323
324 // Stop third party procs
325 $procsKilled = Win32Ps::killBins();
326 if ( !empty( $procsKilled ) ) {
327 $this->writeLog( 'Procs killed:' );
328 $procsKilledSort = array();
329 foreach ( $procsKilled as $proc ) {
331 $procsKilledSort[] = '-> ' . basename( $unixExePath ) . ' (PID ' . $proc[Win32Ps::PROCESS_ID] . ') in ' . $unixExePath;
332 }
333 sort( $procsKilledSort );
334 foreach ( $procsKilledSort as $proc ) {
335 $this->writeLog( $proc );
336 }
337 }
338 }
$proc
Definition ajax.php:43
const STARTUP_KILL_OLD_PROCS_TEXT
static formatUnixPath($path)
const PROCESS_ID
static killBins($refreshProcs=false)
const EXECUTABLE_PATH

References $bearsamppLang, $proc, Win32Ps\EXECUTABLE_PATH, Util\formatUnixPath(), Win32Ps\killBins(), Win32Ps\PROCESS_ID, Lang\STARTUP_KILL_OLD_PROCS_TEXT, and writeLog().

Referenced by processWindow().

+ Here is the caller graph for this function:

◆ processWindow()

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

Processes the main window events during startup.

Parameters
mixed$windowThe window handle.
int$idThe event ID.
mixed$ctrlThe control that triggered the event.
mixed$param1Additional parameter 1.
mixed$param2Additional parameter 2.

Definition at line 72 of file class.action.startup.php.

73 {
74 global $bearsamppRoot, $bearsamppCore, $bearsamppLang, $bearsamppBins, $bearsamppTools, $bearsamppApps, $bearsamppWinbinder;
75
76 // Rotation logs
77 $this->rotationLogs();
78
79 // Clean
80 $this->cleanTmpFolders();
81 $this->cleanOldBehaviors();
82
83 // List procs
84 if ( $bearsamppRoot->getProcs() !== false ) {
85 $this->writeLog( 'List procs:' );
86 $listProcs = array();
87 foreach ( $bearsamppRoot->getProcs() as $proc ) {
89 $listProcs[] = '-> ' . basename( $unixExePath ) . ' (PID ' . $proc[Win32Ps::PROCESS_ID] . ') in ' . $unixExePath;
90 }
91 sort( $listProcs );
92 foreach ( $listProcs as $proc ) {
93 $this->writeLog( $proc );
94 }
95 }
96
97 // List modules
98 $this->writeLog( 'List bins modules:' );
99 foreach ( $bearsamppBins->getAll() as $module ) {
100 if ( !$module->isEnable() ) {
101 $this->writeLog( '-> ' . $module->getName() . ': ' . $bearsamppLang->getValue( Lang::DISABLED ) );
102 }
103 else {
104 $this->writeLog( '-> ' . $module->getName() . ': ' . $module->getVersion() . ' (' . $module->getRelease() . ')' );
105 }
106 }
107 $this->writeLog( 'List tools modules:' );
108 foreach ( $bearsamppTools->getAll() as $module ) {
109 if ( !$module->isEnable() ) {
110 $this->writeLog( '-> ' . $module->getName() . ': ' . $bearsamppLang->getValue( Lang::DISABLED ) );
111 }
112 else {
113 $this->writeLog( '-> ' . $module->getName() . ': ' . $module->getVersion() . ' (' . $module->getRelease() . ')' );
114 }
115 }
116 $this->writeLog( 'List apps modules:' );
117 foreach ( $bearsamppApps->getAll() as $module ) {
118 if ( !$module->isEnable() ) {
119 $this->writeLog( '-> ' . $module->getName() . ': ' . $bearsamppLang->getValue( Lang::DISABLED ) );
120 }
121 else {
122 $this->writeLog( '-> ' . $module->getName() . ': ' . $module->getVersion() . ' (' . $module->getRelease() . ')' );
123 }
124 }
125
126 // Kill old instances
127 $this->killOldInstances();
128
129 // Prepare app
130 $this->refreshHostname();
131 $this->checkLaunchStartup();
132 $this->checkBrowser();
133 $this->sysInfos();
134 $this->refreshAliases();
135 $this->refreshVhosts();
136
137 // Check app path
138 $this->checkPath();
139 $this->scanFolders();
140 $this->changePath();
141 $this->savePath();
142
143 // Check BEARSAMPP_PATH, BEARSAMPP_BINS and System Path reg keys
144 $this->checkPathRegKey();
145 $this->checkBinsRegKey();
146 $this->checkSystemPathRegKey();
147
148 // Update config
149 $this->updateConfig();
150
151 // Create SSL certificates
152 $this->createSslCrts();
153
154 // Install
155 $this->installServices();
156
157 // Actions if everything OK
158 if ( !$this->restart && empty( $this->error ) ) {
159 $this->refreshGitRepos();
160 $this->writeLog( 'Started in ' . round( Util::getMicrotime() - $this->startTime, 3 ) . 's' );
161 }
162 else {
163 $this->splash->incrProgressBar( 2 );
164 }
165
166 if ( $this->restart ) {
167 $this->writeLog( APP_TITLE . ' has to be restarted' );
168 $this->splash->setTextLoading(
169 sprintf(
171 APP_TITLE . ' ' . $bearsamppCore->getAppVersion()
172 )
173 );
174 foreach ( $bearsamppBins->getServices() as $sName => $service ) {
175 $service->delete();
176 }
178 }
179
180 if ( !empty( $this->error ) ) {
181 $this->writeLog( 'Error: ' . $this->error );
182 $bearsamppWinbinder->messageBoxError( $this->error, $bearsamppLang->getValue( Lang::STARTUP_ERROR_TITLE ) );
183 }
184
186 $bearsamppWinbinder->destroyWindow( $window );
187 }
const STARTUP_PREPARE_RESTART_TEXT
const DISABLED
const STARTUP_ERROR_TITLE
static startLoading()

References $bearsamppBins, $bearsamppCore, $bearsamppLang, $bearsamppRoot, $proc, APP_TITLE, changePath(), checkBinsRegKey(), checkBrowser(), checkLaunchStartup(), checkPath(), checkPathRegKey(), checkSystemPathRegKey(), cleanOldBehaviors(), cleanTmpFolders(), createSslCrts(), Lang\DISABLED, Win32Ps\EXECUTABLE_PATH, Util\formatUnixPath(), Util\getMicrotime(), installServices(), killOldInstances(), Win32Ps\PROCESS_ID, refreshAliases(), refreshGitRepos(), refreshHostname(), refreshVhosts(), ActionExec\RESTART, rotationLogs(), savePath(), scanFolders(), Util\startLoading(), Lang\STARTUP_ERROR_TITLE, Lang\STARTUP_PREPARE_RESTART_TEXT, sysInfos(), updateConfig(), and writeLog().

◆ refreshAliases()

ActionStartup::refreshAliases ( )
private

Refreshes the aliases in the Apache configuration.

Definition at line 405 of file class.action.startup.php.

406 {
408
409 $this->splash->setTextLoading( $bearsamppLang->getValue( Lang::STARTUP_REFRESH_ALIAS_TEXT ) );
410 $this->splash->incrProgressBar();
411 $this->writeLog( 'Refresh aliases' );
412
413 $bearsamppBins->getApache()->refreshAlias( $bearsamppConfig->isOnline() );
414 }
const STARTUP_REFRESH_ALIAS_TEXT

References $bearsamppBins, $bearsamppConfig, $bearsamppLang, Lang\STARTUP_REFRESH_ALIAS_TEXT, and writeLog().

Referenced by processWindow().

+ Here is the caller graph for this function:

◆ refreshGitRepos()

ActionStartup::refreshGitRepos ( )
private

Refreshes Git repositories if the scan on startup is enabled. Logs the number of repositories found.

Definition at line 767 of file class.action.startup.php.

768 {
769 global $bearsamppLang, $bearsamppTools;
770
771 $this->splash->incrProgressBar();
772 if ( $bearsamppTools->getGit()->isScanStartup() ) {
773 $this->splash->setTextLoading( $bearsamppLang->getValue( Lang::STARTUP_REFRESH_GIT_REPOS_TEXT ) );
774
775 $repos = $bearsamppTools->getGit()->findRepos( false );
776 $this->writeLog( 'Update GIT repos: ' . count( $repos ) . ' found' );
777 }
778 }
const STARTUP_REFRESH_GIT_REPOS_TEXT

References $bearsamppLang, Lang\STARTUP_REFRESH_GIT_REPOS_TEXT, and writeLog().

Referenced by processWindow().

+ Here is the caller graph for this function:

◆ refreshHostname()

ActionStartup::refreshHostname ( )
private

Refreshes the hostname in the configuration.

Definition at line 343 of file class.action.startup.php.

344 {
346
347 $this->splash->setTextLoading( $bearsamppLang->getValue( Lang::STARTUP_REFRESH_HOSTNAME_TEXT ) );
348 $this->splash->incrProgressBar();
349 $this->writeLog( 'Refresh hostname' );
350
351 $bearsamppConfig->replace( Config::CFG_HOSTNAME, gethostname() );
352 }
const CFG_HOSTNAME
const STARTUP_REFRESH_HOSTNAME_TEXT

References $bearsamppConfig, $bearsamppLang, Config\CFG_HOSTNAME, Lang\STARTUP_REFRESH_HOSTNAME_TEXT, and writeLog().

Referenced by processWindow().

+ Here is the caller graph for this function:

◆ refreshVhosts()

ActionStartup::refreshVhosts ( )
private

Refreshes the virtual hosts in the Apache configuration.

Definition at line 419 of file class.action.startup.php.

420 {
422
423 $this->splash->setTextLoading( $bearsamppLang->getValue( Lang::STARTUP_REFRESH_VHOSTS_TEXT ) );
424 $this->splash->incrProgressBar();
425 $this->writeLog( 'Refresh vhosts' );
426
427 $bearsamppBins->getApache()->refreshVhosts( $bearsamppConfig->isOnline() );
428 }
const STARTUP_REFRESH_VHOSTS_TEXT

References $bearsamppBins, $bearsamppConfig, $bearsamppLang, Lang\STARTUP_REFRESH_VHOSTS_TEXT, and writeLog().

Referenced by processWindow().

+ Here is the caller graph for this function:

◆ rotationLogs()

ActionStartup::rotationLogs ( )
private

Rotates the logs by archiving old logs and purging old archives.

Definition at line 192 of file class.action.startup.php.

193 {
195
196 $this->splash->setTextLoading( $bearsamppLang->getValue( Lang::STARTUP_ROTATION_LOGS_TEXT ) );
197 $this->splash->incrProgressBar();
198
199 $archivesPath = $bearsamppRoot->getLogsPath() . '/archives';
200 if ( !is_dir( $archivesPath ) ) {
201 mkdir( $archivesPath, 0777, true );
202
203 return;
204 }
205
206 $date = date( 'Y-m-d-His', time() );
207 $archiveLogsPath = $archivesPath . '/' . $date;
208 $archiveScriptsPath = $archiveLogsPath . '/scripts';
209
210 // Create archive folders
211 mkdir( $archiveLogsPath, 0777, true );
212 mkdir( $archiveScriptsPath, 0777, true );
213
214 // Count archives
215 $archives = array();
216 $handle = @opendir( $archivesPath );
217 if ( !$handle ) {
218 return;
219 }
220 while ( false !== ($file = readdir( $handle )) ) {
221 if ( $file == '.' || $file == '..' ) {
222 continue;
223 }
224 $archives[] = $archivesPath . '/' . $file;
225 }
226 closedir( $handle );
227 sort( $archives );
228
229 // Remove old archives
230 if ( count( $archives ) > $bearsamppConfig->getMaxLogsArchives() ) {
231 $total = count( $archives ) - $bearsamppConfig->getMaxLogsArchives();
232 for ( $i = 0; $i < $total; $i++ ) {
233 Util::deleteFolder( $archives[$i] );
234 }
235 }
236
237 // Logs
238 $srcPath = $bearsamppRoot->getLogsPath();
239 $handle = @opendir( $srcPath );
240 if ( !$handle ) {
241 return;
242 }
243 while ( false !== ($file = readdir( $handle )) ) {
244 if ( $file == '.' || $file == '..' || is_dir( $srcPath . '/' . $file ) ) {
245 continue;
246 }
247 copy( $srcPath . '/' . $file, $archiveLogsPath . '/' . $file );
248 }
249 closedir( $handle );
250
251 // Scripts
252 $srcPath = $bearsamppCore->getTmpPath();
253 $handle = @opendir( $srcPath );
254 if ( !$handle ) {
255 return;
256 }
257 while ( false !== ($file = readdir( $handle )) ) {
258 if ( $file == '.' || $file == '..' || is_dir( $srcPath . '/' . $file ) ) {
259 continue;
260 }
261 copy( $srcPath . '/' . $file, $archiveScriptsPath . '/' . $file );
262 }
263 closedir( $handle );
264
265 // Purge logs
266 Util::clearFolders( $bearsamppBins->getLogsPath() );
267 Util::clearFolder( $bearsamppRoot->getLogsPath(), array('archives', '.gitignore') );
268 }
const STARTUP_ROTATION_LOGS_TEXT
static deleteFolder($path)
static clearFolders($paths, $exclude=array())

References $bearsamppBins, $bearsamppConfig, $bearsamppCore, $bearsamppLang, $bearsamppRoot, Util\clearFolder(), Util\clearFolders(), Util\deleteFolder(), and Lang\STARTUP_ROTATION_LOGS_TEXT.

Referenced by processWindow().

+ Here is the caller graph for this function:

◆ savePath()

ActionStartup::savePath ( )
private

Saves the current application path.

Definition at line 475 of file class.action.startup.php.

476 {
477 global $bearsamppCore;
478
479 file_put_contents( $bearsamppCore->getLastPath(), $this->rootPath );
480 $this->writeLog( 'Save current path: ' . $this->rootPath );
481 }

References $bearsamppCore, and writeLog().

Referenced by processWindow().

+ Here is the caller graph for this function:

◆ scanFolders()

ActionStartup::scanFolders ( )
private

Scans folders and logs the number of files to scan.

Definition at line 446 of file class.action.startup.php.

447 {
448 global $bearsamppLang;
449
450 $this->splash->setTextLoading( $bearsamppLang->getValue( Lang::STARTUP_SCAN_FOLDERS_TEXT ) );
451 $this->splash->incrProgressBar();
452
453 $this->filesToScan = Util::getFilesToScan();
454 $this->writeLog( 'Files to scan: ' . count( $this->filesToScan ) );
455 }
const STARTUP_SCAN_FOLDERS_TEXT
static getFilesToScan($path=null)

References $bearsamppLang, Util\getFilesToScan(), Lang\STARTUP_SCAN_FOLDERS_TEXT, and writeLog().

Referenced by processWindow().

+ Here is the caller graph for this function:

◆ sysInfos()

ActionStartup::sysInfos ( )
private

Logs system information.

Definition at line 391 of file class.action.startup.php.

392 {
393 global $bearsamppLang;
394
395 $this->splash->setTextLoading( $bearsamppLang->getValue( Lang::STARTUP_SYS_INFOS ) );
396 $this->splash->incrProgressBar();
397
398 $os = Batch::getOsInfo();
399 $this->writeLog( sprintf( 'OS: %s', $os ) );
400 }
static getOsInfo()
const STARTUP_SYS_INFOS

References $bearsamppLang, Batch\getOsInfo(), Lang\STARTUP_SYS_INFOS, and writeLog().

Referenced by processWindow().

+ Here is the caller graph for this function:

◆ updateConfig()

ActionStartup::updateConfig ( )
private

Updates the configuration for bins, tools, and apps. Logs the update process.

Definition at line 591 of file class.action.startup.php.

592 {
593 global $bearsamppLang, $bearsamppBins, $bearsamppTools, $bearsamppApps;
594
595 $this->splash->setTextLoading( $bearsamppLang->getValue( Lang::STARTUP_UPDATE_CONFIG_TEXT ) );
596 $this->splash->incrProgressBar();
597 $this->writeLog( 'Update config' );
598
599 $bearsamppBins->update();
600 $bearsamppTools->update();
601 $bearsamppApps->update();
602 }
const STARTUP_UPDATE_CONFIG_TEXT

References $bearsamppBins, $bearsamppLang, Lang\STARTUP_UPDATE_CONFIG_TEXT, and writeLog().

Referenced by processWindow().

+ Here is the caller graph for this function:

◆ writeLog()

ActionStartup::writeLog ( $log)
private

Writes a log message to the startup log file.

Parameters
string$logThe log message to write.

Definition at line 785 of file class.action.startup.php.

786 {
787 global $bearsamppRoot;
788 Util::logDebug( $log, $bearsamppRoot->getStartupLogFilePath() );
789 }
static logDebug($data, $file=null)

References $bearsamppRoot, and Util\logDebug().

Referenced by __construct(), changePath(), checkBinsRegKey(), checkBrowser(), checkLaunchStartup(), checkPath(), checkPathRegKey(), checkSystemPathRegKey(), cleanOldBehaviors(), cleanTmpFolders(), installServices(), killOldInstances(), processWindow(), refreshAliases(), refreshGitRepos(), refreshHostname(), refreshVhosts(), savePath(), scanFolders(), sysInfos(), and updateConfig().

+ Here is the caller graph for this function:

Field Documentation

◆ $error

ActionStartup::$error
private

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

◆ $filesToScan

ActionStartup::$filesToScan
private

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

◆ $restart

ActionStartup::$restart
private

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

◆ $rootPath

ActionStartup::$rootPath
private

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

◆ $splash

ActionStartup::$splash
private

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

◆ $startTime

ActionStartup::$startTime
private

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

◆ GAUGE_OTHERS

const ActionStartup::GAUGE_OTHERS = 19

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

◆ GAUGE_SERVICES

const ActionStartup::GAUGE_SERVICES = 5

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


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