mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-03 07:28:57 +02:00
N°9144 Adding StepSequencer
This commit is contained in:
76
setup/StepSequencer.php
Normal file
76
setup/StepSequencer.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?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);
|
||||
}
|
||||
Reference in New Issue
Block a user