Files
iTop/setup/StepSequencer.php
2026-02-12 09:10:43 +01:00

78 lines
1.9 KiB
PHP

<?php
abstract class StepSequencer
{
public const OK = 1;
public const ERROR = 2;
public const WARNING = 3;
public const INFO = 4;
/**
* Runs all the installation steps in one go and directly outputs
* some information about the progress and the success of the various
* sequential steps.
*
* @param bool $bVerbose
* @param string|null $sMessage
* @param string|null $sComment
*
* @return boolean True if the installation was successful, false otherwise
*/
public function ExecuteAllSteps($bVerbose = true, &$sMessage = null, $sComment = null)
{
$sStep = '';
$sStepLabel = '';
$iOverallStatus = self::OK;
do {
if ($bVerbose) {
if ($sStep != '') {
echo "$sStepLabel\n";
echo "Executing '$sStep'\n";
} else {
echo "Starting...\n";
}
}
$aRes = $this->ExecuteStep($sStep, $sComment);
$sStep = $aRes['next-step'];
$sStepLabel = $aRes['next-step-label'];
$sMessage = $aRes['message'];
if ($bVerbose) {
switch ($aRes['status']) {
case self::OK:
echo "Ok. ".$aRes['percentage-completed']." % done.\n";
break;
case self::ERROR:
$iOverallStatus = self::ERROR;
echo "Error: ".$aRes['message']."\n";
break;
case self::WARNING:
$iOverallStatus = self::WARNING;
echo "Warning: ".$aRes['message']."\n";
echo $aRes['percentage-completed']." % done.\n";
break;
case self::INFO:
echo "Info: ".$aRes['message']."\n";
echo $aRes['percentage-completed']." % done.\n";
break;
}
} else {
switch ($aRes['status']) {
case self::ERROR:
$iOverallStatus = self::ERROR;
break;
case self::WARNING:
$iOverallStatus = self::WARNING;
break;
}
}
} while (($aRes['status'] != self::ERROR) && ($aRes['next-step'] != ''));
return ($iOverallStatus == self::OK);
}
abstract public function ExecuteStep($sStep = '', $sComment = null);
}