From 2f14b341e8b6b17626072ce651568ada3cef30b7 Mon Sep 17 00:00:00 2001 From: Timothee Date: Thu, 12 Feb 2026 11:19:21 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B09144=20Fix=20unit=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ModelReflectionSerializer.php | 2 +- setup/feature_removal/SetupAudit.php | 17 ++--------------- setup/feature_removal/get_model_reflection.php | 2 +- setup/wizardcontroller.class.inc.php | 2 +- setup/wizardsteps/AbstractWizStepInstall.php | 17 +++++++++++++++++ setup/wizardsteps/WizStepAdminAccount.php | 2 +- setup/wizardsteps/WizStepDBParams.php | 2 +- setup/wizardsteps/WizStepDataAudit.php | 2 +- setup/wizardsteps/WizStepDetectedInfo.php | 2 +- setup/wizardsteps/WizStepDone.php | 2 +- setup/wizardsteps/WizStepInstall.php | 2 +- setup/wizardsteps/WizStepInstallMiscParams.php | 2 +- setup/wizardsteps/WizStepInstallOrUpgrade.php | 2 +- setup/wizardsteps/WizStepLicense.php | 2 +- setup/wizardsteps/WizStepLicense2.php | 2 +- setup/wizardsteps/WizStepModulesChoice.php | 16 +++++++++++++--- setup/wizardsteps/WizStepSummary.php | 2 +- setup/wizardsteps/WizStepUpgradeMiscParams.php | 2 +- setup/wizardsteps/WizStepWelcome.php | 2 +- setup/wizardsteps/WizardStep.php | 2 +- 20 files changed, 49 insertions(+), 35 deletions(-) diff --git a/setup/feature_removal/ModelReflectionSerializer.php b/setup/feature_removal/ModelReflectionSerializer.php index 6733bda45..62ac160d2 100644 --- a/setup/feature_removal/ModelReflectionSerializer.php +++ b/setup/feature_removal/ModelReflectionSerializer.php @@ -38,7 +38,7 @@ class ModelReflectionSerializer $sOutput = ""; $iRes = 0; - $sCommandLine = sprintf("$sPHPExec %s/get_model_reflection.php --env='%s'", __DIR__, $sEnv); + $sCommandLine = sprintf("$sPHPExec %s/get_model_reflection.php --env=%s", __DIR__, $sEnv); exec($sCommandLine, $sOutput, $iRes); if ($iRes != 0) { $this->LogErrorWithProperLogger("Cannot get classes", null, ['env' => $sEnv, 'code' => $iRes, "output" => $sOutput]); diff --git a/setup/feature_removal/SetupAudit.php b/setup/feature_removal/SetupAudit.php index b30b053ae..1252491b6 100644 --- a/setup/feature_removal/SetupAudit.php +++ b/setup/feature_removal/SetupAudit.php @@ -29,21 +29,8 @@ class SetupAudit extends AbstractSetupAudit return; } - $sCurrentEnv = MetaModel::GetEnvironment(); - - $sConfFile = utils::GetConfigFilePath($sCurrentEnv); - MetaModel::Startup($sConfFile, false /* $bModelOnly */, false /* $bAllowCache */, false /* $bTraceSourceFiles */, $sCurrentEnv); - if ($sCurrentEnv === $this->sEnvBefore) { - $this->aClassesBefore = MetaModel::GetClasses(); - } else { - $this->aClassesBefore = ModelReflectionSerializer::GetInstance()->GetModelFromEnvironment($this->sEnvBefore); - } - - if ($sCurrentEnv === $this->sEnvAfter) { - $this->aClassesAfter = MetaModel::GetClasses(); - } else { - $this->aClassesAfter = ModelReflectionSerializer::GetInstance()->GetModelFromEnvironment($this->sEnvAfter); - } + $this->aClassesBefore = ModelReflectionSerializer::GetInstance()->GetModelFromEnvironment($this->sEnvBefore); + $this->aClassesAfter = ModelReflectionSerializer::GetInstance()->GetModelFromEnvironment($this->sEnvAfter); $this->bClassesInitialized = true; } diff --git a/setup/feature_removal/get_model_reflection.php b/setup/feature_removal/get_model_reflection.php index 7648b2c92..92f99e906 100644 --- a/setup/feature_removal/get_model_reflection.php +++ b/setup/feature_removal/get_model_reflection.php @@ -5,7 +5,7 @@ require_once(APPROOT.'application/application.inc.php'); $sEnv = null; if (isset($argv)) { foreach ($argv as $iArg => $sArg) { - if (preg_match('/^--env=\'(.*)\'$/', $sArg, $aMatches)) { + if (preg_match('/^--env=(.*)$/', $sArg, $aMatches)) { $sEnv = $aMatches[1]; } } diff --git a/setup/wizardcontroller.class.inc.php b/setup/wizardcontroller.class.inc.php index 80c771873..4df05dfa9 100644 --- a/setup/wizardcontroller.class.inc.php +++ b/setup/wizardcontroller.class.inc.php @@ -176,7 +176,7 @@ class WizardController $this->PushStep(['class' => $sCurrentStepClass, 'state' => $sCurrentState]); } $aPossibleSteps = $oStep->GetPossibleSteps(); - $aNextStepInfo = $oStep->ProcessParams(true); // true => moving forward + $aNextStepInfo = $oStep->UpdateWizardStateAndGetNextStep(true); // true => moving forward if (in_array($aNextStepInfo['class'], $aPossibleSteps)) { $oNextStep = new $aNextStepInfo['class']($this, $aNextStepInfo['state']); $this->DisplayStep($oNextStep); diff --git a/setup/wizardsteps/AbstractWizStepInstall.php b/setup/wizardsteps/AbstractWizStepInstall.php index bd4394ddb..58deb024d 100644 --- a/setup/wizardsteps/AbstractWizStepInstall.php +++ b/setup/wizardsteps/AbstractWizStepInstall.php @@ -1,4 +1,21 @@ oWizard->SaveParameter('admin_user', ''); $this->oWizard->SaveParameter('admin_pwd', ''); diff --git a/setup/wizardsteps/WizStepDBParams.php b/setup/wizardsteps/WizStepDBParams.php index c2e97b82c..3911ab353 100644 --- a/setup/wizardsteps/WizStepDBParams.php +++ b/setup/wizardsteps/WizStepDBParams.php @@ -35,7 +35,7 @@ class WizStepDBParams extends WizardStep return ['WizStepAdminAccount']; } - public function ProcessParams($bMoveForward = true) + public function UpdateWizardStateAndGetNextStep($bMoveForward = true) { $this->oWizard->SaveParameter('db_server', ''); $this->oWizard->SaveParameter('db_user', ''); diff --git a/setup/wizardsteps/WizStepDataAudit.php b/setup/wizardsteps/WizStepDataAudit.php index f79e93504..f916000a4 100644 --- a/setup/wizardsteps/WizStepDataAudit.php +++ b/setup/wizardsteps/WizStepDataAudit.php @@ -52,7 +52,7 @@ class WizStepDataAudit extends WizStepInstall } - public function ProcessParams($bMoveForward = true) + public function UpdateWizardStateAndGetNextStep($bMoveForward = true) { return ['class' => 'WizStepSummary', 'state' => '']; } diff --git a/setup/wizardsteps/WizStepDetectedInfo.php b/setup/wizardsteps/WizStepDetectedInfo.php index 791bda64d..9885d65fb 100644 --- a/setup/wizardsteps/WizStepDetectedInfo.php +++ b/setup/wizardsteps/WizStepDetectedInfo.php @@ -36,7 +36,7 @@ class WizStepDetectedInfo extends WizardStep return ['WizStepUpgradeMiscParams', 'WizStepLicense2']; } - public function ProcessParams($bMoveForward = true) + public function UpdateWizardStateAndGetNextStep($bMoveForward = true) { $sUpgradeType = utils::ReadParam('upgrade_type'); diff --git a/setup/wizardsteps/WizStepDone.php b/setup/wizardsteps/WizStepDone.php index d097434a3..78ad1eca5 100644 --- a/setup/wizardsteps/WizStepDone.php +++ b/setup/wizardsteps/WizStepDone.php @@ -34,7 +34,7 @@ class WizStepDone extends WizardStep return []; } - public function ProcessParams($bMoveForward = true) + public function UpdateWizardStateAndGetNextStep($bMoveForward = true) { return ['class' => '', 'state' => '']; } diff --git a/setup/wizardsteps/WizStepInstall.php b/setup/wizardsteps/WizStepInstall.php index d74a86075..c01ad78cc 100644 --- a/setup/wizardsteps/WizStepInstall.php +++ b/setup/wizardsteps/WizStepInstall.php @@ -51,7 +51,7 @@ class WizStepInstall extends AbstractWizStepInstall } } - public function ProcessParams($bMoveForward = true) + public function UpdateWizardStateAndGetNextStep($bMoveForward = true) { return ['class' => 'WizStepDone', 'state' => '']; } diff --git a/setup/wizardsteps/WizStepInstallMiscParams.php b/setup/wizardsteps/WizStepInstallMiscParams.php index 5087b7298..79d038e69 100644 --- a/setup/wizardsteps/WizStepInstallMiscParams.php +++ b/setup/wizardsteps/WizStepInstallMiscParams.php @@ -35,7 +35,7 @@ class WizStepInstallMiscParams extends AbstractWizStepMiscParams return ['WizStepModulesChoice']; } - public function ProcessParams($bMoveForward = true) + public function UpdateWizardStateAndGetNextStep($bMoveForward = true) { $this->oWizard->SaveParameter('default_language', ''); $this->oWizard->SaveParameter('application_url', ''); diff --git a/setup/wizardsteps/WizStepInstallOrUpgrade.php b/setup/wizardsteps/WizStepInstallOrUpgrade.php index 065521514..959764b86 100644 --- a/setup/wizardsteps/WizStepInstallOrUpgrade.php +++ b/setup/wizardsteps/WizStepInstallOrUpgrade.php @@ -34,7 +34,7 @@ class WizStepInstallOrUpgrade extends WizardStep return ['WizStepDetectedInfo', 'WizStepLicense']; } - public function ProcessParams($bMoveForward = true) + public function UpdateWizardStateAndGetNextStep($bMoveForward = true) { $sNextStep = ''; $sInstallMode = utils::ReadParam('install_mode'); diff --git a/setup/wizardsteps/WizStepLicense.php b/setup/wizardsteps/WizStepLicense.php index 56079e55e..c4ad6b234 100644 --- a/setup/wizardsteps/WizStepLicense.php +++ b/setup/wizardsteps/WizStepLicense.php @@ -35,7 +35,7 @@ class WizStepLicense extends WizardStep return ['WizStepDBParams']; } - public function ProcessParams($bMoveForward = true) + public function UpdateWizardStateAndGetNextStep($bMoveForward = true) { $this->oWizard->SaveParameter('accept_license', 'no'); return ['class' => 'WizStepDBParams', 'state' => '']; diff --git a/setup/wizardsteps/WizStepLicense2.php b/setup/wizardsteps/WizStepLicense2.php index ff6c60fc5..2115f81e4 100644 --- a/setup/wizardsteps/WizStepLicense2.php +++ b/setup/wizardsteps/WizStepLicense2.php @@ -28,7 +28,7 @@ class WizStepLicense2 extends WizStepLicense return ['WizStepUpgradeMiscParams']; } - public function ProcessParams($bMoveForward = true) + public function UpdateWizardStateAndGetNextStep($bMoveForward = true) { return ['class' => 'WizStepUpgradeMiscParams', 'state' => '']; } diff --git a/setup/wizardsteps/WizStepModulesChoice.php b/setup/wizardsteps/WizStepModulesChoice.php index 7f3cc1715..b2b0a7a61 100644 --- a/setup/wizardsteps/WizStepModulesChoice.php +++ b/setup/wizardsteps/WizStepModulesChoice.php @@ -118,7 +118,17 @@ class WizStepModulesChoice extends WizardStep return [$aExtensionsAdded, $aExtensionsRemoved, $aExtensionsNotUninstallable]; } - public function ProcessParams($bMoveForward = true) + public function IsDataAuditEnabled(): bool { + $sPath = APPROOT.'env-production'; + if (!is_dir($sPath)) { + SetupLog::Info("Reinstallation of an iTop from a backup (No env-production found). Setup data audit disabled"); + + return false; + } + return true; + } + + public function UpdateWizardStateAndGetNextStep($bMoveForward = true) { // Accumulates the selected modules: $index = $this->GetStepIndex(); @@ -156,7 +166,7 @@ class WizStepModulesChoice extends WizardStep $this->oWizard->SetParameter('removed_extensions', json_encode($aExtensionsRemoved)); $this->oWizard->SetParameter('extensions_not_uninstallable', json_encode(array_keys($aExtensionsNotUninstallable))); $sMode = $this->oWizard->GetParameter('mode', 'install'); - if ($sMode == 'install') { + if ($sMode == 'install' || !$this->IsDataAuditEnabled()) { return ['class' => 'WizStepSummary', 'state' => '']; } else { return ['class' => 'WizStepDataAudit', 'state' => '']; @@ -824,7 +834,7 @@ EOF return 'Non-uninstallable extension missing'; } - if ($this->GetStepInfo(1 + $this->GetStepIndex()) === null) { + if ($this->GetStepInfo(1 + $this->GetStepIndex()) === null && $this->IsDataAuditEnabled()) { return 'Check compatibility'; } diff --git a/setup/wizardsteps/WizStepSummary.php b/setup/wizardsteps/WizStepSummary.php index 0acaf28cd..afce2cdd6 100644 --- a/setup/wizardsteps/WizStepSummary.php +++ b/setup/wizardsteps/WizStepSummary.php @@ -58,7 +58,7 @@ class WizStepSummary extends AbstractWizStepInstall } } - public function ProcessParams($bMoveForward = true) + public function UpdateWizardStateAndGetNextStep($bMoveForward = true) { $this->oWizard->SaveParameter('db_backup', false); $this->oWizard->SaveParameter('db_backup_path', ''); diff --git a/setup/wizardsteps/WizStepUpgradeMiscParams.php b/setup/wizardsteps/WizStepUpgradeMiscParams.php index 82a88d8c9..38121e419 100644 --- a/setup/wizardsteps/WizStepUpgradeMiscParams.php +++ b/setup/wizardsteps/WizStepUpgradeMiscParams.php @@ -34,7 +34,7 @@ class WizStepUpgradeMiscParams extends AbstractWizStepMiscParams return ['WizStepModulesChoice']; } - public function ProcessParams($bMoveForward = true) + public function UpdateWizardStateAndGetNextStep($bMoveForward = true) { $this->oWizard->SaveParameter('application_url', ''); $this->oWizard->SaveParameter('graphviz_path', ''); diff --git a/setup/wizardsteps/WizStepWelcome.php b/setup/wizardsteps/WizStepWelcome.php index 6b4e68044..9307c06fc 100644 --- a/setup/wizardsteps/WizStepWelcome.php +++ b/setup/wizardsteps/WizStepWelcome.php @@ -46,7 +46,7 @@ class WizStepWelcome extends WizardStep return ['WizStepInstallOrUpgrade']; } - public function ProcessParams($bMoveForward = true) + public function UpdateWizardStateAndGetNextStep($bMoveForward = true) { $sUID = SetupUtils::CreateSetupToken(); $this->oWizard->SetParameter('authent', $sUID); diff --git a/setup/wizardsteps/WizardStep.php b/setup/wizardsteps/WizardStep.php index 464dfff02..878c204c7 100644 --- a/setup/wizardsteps/WizardStep.php +++ b/setup/wizardsteps/WizardStep.php @@ -106,7 +106,7 @@ abstract class WizardStep * @param bool $bMoveForward True if the wizard is moving forward 'Next >>' button pressed, false otherwise * @return hash array('class' => $sNextClass, 'state' => $sNextState) */ - abstract public function ProcessParams($bMoveForward = true); + abstract public function UpdateWizardStateAndGetNextStep($bMoveForward = true); /** * Returns the list of possible steps from this step forward