N°9144 Adding StepSequencer

This commit is contained in:
Timothee
2026-01-28 10:44:56 +01:00
parent a54b11c933
commit fd6ce5f5c4
6 changed files with 97 additions and 91 deletions

View File

@@ -682,9 +682,6 @@ body {
overflow: auto;
text-align: center;
}
#installation_progress {
display: none;
}
#fresh_content{
border: 0;
min-height: 300px;

76
setup/StepSequencer.php Normal file
View 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);
}

View File

@@ -21,6 +21,7 @@ use Combodo\iTop\Setup\FeatureRemoval\InplaceSetupAudit;
use Combodo\iTop\Setup\FeatureRemoval\ModelReflectionSerializer;
require_once(APPROOT.'setup/parameters.class.inc.php');
require_once(APPROOT.'setup/StepSequencer.php');
require_once(APPROOT.'setup/xmldataloader.class.inc.php');
require_once(APPROOT.'setup/backup.class.inc.php');
require_once APPROOT.'setup/feature_removal/InplaceSetupAudit.php';
@@ -39,12 +40,8 @@ require_once APPROOT.'setup/feature_removal/InplaceSetupAudit.php';
* @license http://opensource.org/licenses/AGPL-3.0
*/
class ApplicationInstaller
class ApplicationBuildSequencer extends StepSequencer
{
public const OK = 1;
public const ERROR = 2;
public const WARNING = 3;
public const INFO = 4;
/** @var \Parameters */
protected $oParams;
@@ -90,71 +87,7 @@ class ApplicationInstaller
return 'env-'.$sTargetEnv;
}
/**
* 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 $sInstallComment
*
* @return boolean True if the installation was successful, false otherwise
*/
public function ExecuteAllSteps($bVerbose = true, &$sMessage = null, $sInstallComment = null)
{
$sStep = '';
$sStepLabel = '';
$iOverallStatus = self::OK;
do {
if ($bVerbose) {
if ($sStep != '') {
echo "$sStepLabel\n";
echo "Executing '$sStep'\n";
} else {
echo "Starting the installation...\n";
}
}
$aRes = $this->ExecuteStep($sStep, $sInstallComment);
$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);
}
private function GetConfig()
{
@@ -1100,3 +1033,8 @@ class SetupDBBackup extends DBBackup
SetupLog::Ok('Error - '.$sMsg);
}
}
/**
* For compatibility with older scripts
*/
class_alias('ApplicationBuildSequencer', 'ApplicationInstaller');

View File

@@ -272,7 +272,7 @@ $bFoundIssues = false;
$bInstall = utils::ReadParam('install', true, true /* CLI allowed */);
if ($bInstall) {
echo "Starting the unattended installation...\n";
$oWizard = new ApplicationInstaller($oParams);
$oWizard = new ApplicationBuildSequencer($oParams);
$bRes = $oWizard->ExecuteAllSteps();
if (!$bRes) {
echo "\nencountered installation issues!";

View File

@@ -18,6 +18,9 @@
*/
use Combodo\iTop\Application\WebPage\WebPage;
/**
* @since 3.3.0
*/
class WizStepAudit extends AbstractWizStepBuild
{
public function GetTitle()
@@ -58,9 +61,9 @@ class WizStepAudit extends AbstractWizStepBuild
$sStep = $aParameters['installer_step'];
$sJSONParameters = $aParameters['installer_config'];
$oParameters->LoadFromHash(json_decode($sJSONParameters, true /* bAssoc */));
$oInstaller = new ApplicationInstaller($oParameters);
$oInstaller = new ApplicationBuildSequencer($oParameters);
$aRes = $oInstaller->ExecuteStep($sStep);
if (($aRes['status'] != ApplicationInstaller::ERROR) && ($aRes['next-step'] != '')) {
if (($aRes['status'] != ApplicationBuildSequencer::ERROR) && ($aRes['next-step'] != '')) {
// Tell the web page to move the progress bar and to launch the next step
$sMessage = addslashes(utils::EscapeHtml($aRes['next-step-label']));
$oPage->add_ready_script(
@@ -74,7 +77,7 @@ class WizStepAudit extends AbstractWizStepBuild
ExecuteStep('{$aRes['next-step']}');
EOF
);
} elseif ($aRes['status'] != ApplicationInstaller::ERROR) {
} elseif ($aRes['status'] != ApplicationBuildSequencer::ERROR) {
// Installation complete, move to the next step of the wizard
$oPage->add_ready_script(
<<<EOF

View File

@@ -54,7 +54,7 @@ class WizStepBuild extends AbstractWizStepBuild
*/
public function GetNextButtonLabel()
{
return 'Install';
return 'Continue';
}
public function CanMoveForward()
@@ -95,16 +95,8 @@ class WizStepBuild extends AbstractWizStepBuild
$oPage->add_ready_script(
<<<JS
$("#params_summary div").addClass('closed');
$("#params_summary .title").on('click', function() { $(this).parent().toggleClass('closed'); } );
$("#btn_next").on("click.install", function(event) {
$('#summary').hide();
$('#installation_progress').show();
$(this).prop('disabled', true);
event.preventDefault();
ExecuteStep("");
});
$("#wiz_form").data("installation_status", "not started")
$("#wiz_form").data("installation_status", "not started");
ExecuteStep("");
JS
);
}
@@ -116,9 +108,9 @@ JS
$sStep = $aParameters['installer_step'];
$sJSONParameters = $aParameters['installer_config'];
$oParameters->LoadFromHash(json_decode($sJSONParameters, true /* bAssoc */));
$oInstaller = new ApplicationInstaller($oParameters);
$oInstaller = new ApplicationBuildSequencer($oParameters);
$aRes = $oInstaller->ExecuteStep($sStep);
if (($aRes['status'] != ApplicationInstaller::ERROR) && ($aRes['next-step'] != '')) {
if (($aRes['status'] != ApplicationBuildSequencer::ERROR) && ($aRes['next-step'] != '')) {
// Tell the web page to move the progress bar and to launch the next step
$sMessage = addslashes(utils::EscapeHtml($aRes['next-step-label']));
$oPage->add_ready_script(
@@ -132,7 +124,7 @@ JS
ExecuteStep('{$aRes['next-step']}');
EOF
);
} elseif ($aRes['status'] != ApplicationInstaller::ERROR) {
} elseif ($aRes['status'] != ApplicationBuildSequencer::ERROR) {
// Installation complete, move to the next step of the wizard
$oPage->add_ready_script(
<<<EOF
@@ -162,7 +154,7 @@ EOF
*/
public function JSCanMoveForward()
{
return 'return (($("#wiz_form").data("installation_status") === "not started") || ($("#wiz_form").data("installation_status") === "completed"));';
return 'return $("#wiz_form").data("installation_status") === "completed";';
}
/**