From 1a57a427c05af10f8f2ee72c3c2c98e2f0c1e679 Mon Sep 17 00:00:00 2001 From: Lenaick Date: Tue, 9 Jun 2026 14:29:06 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B09454=20-=20Make=20MTT=20compatible=20wit?= =?UTF-8?q?h=20the=20dry=20run=20(#931)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * N°9454 - Make MTT compatible with the dry run * N°9454 - Make MTT compatible with the dry run * N°9454 - Cleaning up configuration handling * N°9454 - Cleanup code * N°9454 - Remove writable directories * Update setup/wizardsteps/WizStepLandingBeforeAudit.php Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * Update setup/runtimeenv.class.inc.php Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * N°9454 - Secure target environment wizard step done form submission --------- Co-authored-by: Eric Espie Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- core/metamodel.class.php | 10 +++-- .../DataFeatureRemovalController.php | 3 +- setup/compiler.class.inc.php | 34 ++++---------- .../DryRemovalRuntimeEnvironment.php | 2 +- setup/runtimeenv.class.inc.php | 33 +++++++------- setup/sequencers/StepSequencer.php | 7 +-- setup/setuputils.class.inc.php | 15 +++++-- .../InstallationFileService.php | 5 ++- setup/wizardsteps/AbstractWizStepInstall.php | 2 +- setup/wizardsteps/WizStepDataAudit.php | 7 +-- setup/wizardsteps/WizStepDone.php | 6 ++- .../wizardsteps/WizStepLandingBeforeAudit.php | 45 ++++++++++++------- setup/wizardsteps/WizStepModulesChoice.php | 8 ++-- 13 files changed, 94 insertions(+), 83 deletions(-) diff --git a/core/metamodel.class.php b/core/metamodel.class.php index 9fe20e3c6..540ae3d8e 100644 --- a/core/metamodel.class.php +++ b/core/metamodel.class.php @@ -22,7 +22,6 @@ use Combodo\iTop\Application\EventRegister\ApplicationEvents; use Combodo\iTop\Core\MetaModel\FriendlyNameType; use Combodo\iTop\Service\Events\EventData; use Combodo\iTop\Service\Events\EventService; -use Combodo\iTop\Setup\ModuleDependency\Module; use Combodo\iTop\Setup\ModuleDiscovery\ModuleFileReader; require_once APPROOT.'core/modulehandler.class.inc.php'; @@ -4660,12 +4659,15 @@ abstract class MetaModel * @throws \CoreException * @throws \MySQLException */ - public static function DBExists($bMustBeComplete = true) + public static function DBExists($bMustBeComplete = true, ?string $sDBName = null) { - if (!CMDBSource::IsDB(self::$m_sDBName)) { + if (is_null($sDBName)) { + $sDBName = self::$m_sDBName; + } + if (!CMDBSource::IsDB($sDBName)) { return false; } - CMDBSource::SelectDB(self::$m_sDBName); + CMDBSource::SelectDB($sDBName); $aFound = []; $aMissing = []; diff --git a/datamodels/2.x/combodo-data-feature-removal/src/Controller/DataFeatureRemovalController.php b/datamodels/2.x/combodo-data-feature-removal/src/Controller/DataFeatureRemovalController.php index 77cfabeb8..c1880c8e8 100644 --- a/datamodels/2.x/combodo-data-feature-removal/src/Controller/DataFeatureRemovalController.php +++ b/datamodels/2.x/combodo-data-feature-removal/src/Controller/DataFeatureRemovalController.php @@ -98,7 +98,7 @@ class DataFeatureRemovalController extends Controller $aHiddenInputNames = [ 'selected_extensions' => '[]', 'selected_modules' => '[]', - 'display_choices' => '[]', + 'display_choices' => '', 'added_extensions' => '[]', 'removed_extensions' => '[]', 'extensions_not_uninstallable' => '[]', @@ -106,6 +106,7 @@ class DataFeatureRemovalController extends Controller 'force-uninstall' => "", 'use_symbolic_links' => MFCompiler::UseSymbolicLinks() ? 'on' : '', 'return_button_label' => '', + 'target_env' => ITOP_DEFAULT_ENV, ]; $aHiddenInputs = []; diff --git a/setup/compiler.class.inc.php b/setup/compiler.class.inc.php index a51cd4862..16a8d0992 100644 --- a/setup/compiler.class.inc.php +++ b/setup/compiler.class.inc.php @@ -20,7 +20,6 @@ use Combodo\iTop\Application\Branding; use Combodo\iTop\Application\WebPage\iTopWebPage; -use Combodo\iTop\Application\WebPage\Page; use Combodo\iTop\DesignDocument; use Combodo\iTop\DesignElement; use Combodo\iTop\PropertyType\PropertyTypeDesign; @@ -264,14 +263,13 @@ class MFCompiler * Compile the data model into PHP files and data structures * * @param string $sTargetDir The target directory where to put the resulting files - * @param Page $oP For some output... * @param bool $bUseSymbolicLinks * @param bool $bSkipTempDir * * @return void * @throws Exception */ - public function Compile($sTargetDir, $oP = null, $bUseSymbolicLinks = null, $bSkipTempDir = false, $bEnterMaintenanceMode = true) + public function Compile($sTargetDir, $bUseSymbolicLinks = null, $bSkipTempDir = false) { if (is_null($bUseSymbolicLinks)) { $bUseSymbolicLinks = false; @@ -283,16 +281,7 @@ class MFCompiler } $sFinalTargetDir = $sTargetDir; - $bIsAlreadyInMaintenanceMode = SetupUtils::IsInMaintenanceMode(); - $sConfigFilePath = utils::GetConfigFilePath($this->sEnvironment); - if (is_file($sConfigFilePath)) { - $oConfig = new Config($sConfigFilePath); - } else { - $oConfig = null; - } - if (($this->sEnvironment == ITOP_DEFAULT_ENV) && !$bIsAlreadyInMaintenanceMode && $bEnterMaintenanceMode) { - SetupUtils::EnterMaintenanceMode($oConfig); - } + if ($bUseSymbolicLinks || $bSkipTempDir) { // Skip the creation of a temporary dictionary, not compatible with symbolic links $sTempTargetDir = $sFinalTargetDir; @@ -307,15 +296,13 @@ class MFCompiler } try { - $this->DoCompile($sTempTargetDir, $sFinalTargetDir, $oP = null, $bUseSymbolicLinks); + $this->DoCompile($sTempTargetDir, $sFinalTargetDir, $bUseSymbolicLinks); } catch (Exception $e) { if ($sTempTargetDir != $sFinalTargetDir) { // Cleanup the temporary directory SetupUtils::rrmdir($sTempTargetDir); } - if (($this->sEnvironment == ITOP_DEFAULT_ENV) && !$bIsAlreadyInMaintenanceMode && $bEnterMaintenanceMode) { - SetupUtils::ExitMaintenanceMode(); - } + throw $e; } @@ -323,9 +310,6 @@ class MFCompiler // Move the results to the target directory SetupUtils::movedir($sTempTargetDir, $sFinalTargetDir); } - if (($this->sEnvironment == ITOP_DEFAULT_ENV) && !$bIsAlreadyInMaintenanceMode && $bEnterMaintenanceMode) { - SetupUtils::ExitMaintenanceMode(); - } // Reset the opcache since otherwise the PHP "model" files may still be cached !! // In case of bad luck (this happens **sometimes** - see N. 550), we may analyze the database structure @@ -343,13 +327,14 @@ class MFCompiler /** * Perform the actual "Compilation" of all modules + * * @param string $sTempTargetDir * @param string $sFinalTargetDir - * @param Page $oP * @param bool $bUseSymbolicLinks + * * @throws Exception */ - protected function DoCompile($sTempTargetDir, $sFinalTargetDir, $oP = null, $bUseSymbolicLinks = false) + protected function DoCompile($sTempTargetDir, $sFinalTargetDir, $bUseSymbolicLinks = false) { $aAllClasses = []; // flat list of classes $aModulesInfo = []; // Hash array of module_name => array('version' => string, 'root_dir' => string) @@ -538,7 +523,7 @@ EOF; } try { /** @var iTopWebPage $oP */ - $aMenuLines = $this->CompileMenu($oMenuNode, $sTempTargetDir, $sFinalTargetDir, $sRelativeDir, $oP); + $aMenuLines = $this->CompileMenu($oMenuNode, $sTempTargetDir, $sFinalTargetDir, $sRelativeDir); } catch (DOMFormatException $e) { throw new Exception("Failed to process menu '$sMenuId', from '$sModuleRootDir': ".$e->getMessage()); } @@ -2581,13 +2566,12 @@ CSS; * @param string $sTempTargetDir * @param string $sFinalTargetDir * @param string $sModuleRelativeDir - * @param iTopWebPage $oP * * @return array * @throws \DOMException * @throws \DOMFormatException */ - protected function CompileMenu($oMenu, $sTempTargetDir, $sFinalTargetDir, $sModuleRelativeDir, $oP) + protected function CompileMenu($oMenu, $sTempTargetDir, $sFinalTargetDir, $sModuleRelativeDir) { $this->CompileFiles($oMenu, $sTempTargetDir.'/'.$sModuleRelativeDir, $sFinalTargetDir.'/'.$sModuleRelativeDir, $sModuleRelativeDir); diff --git a/setup/feature_removal/DryRemovalRuntimeEnvironment.php b/setup/feature_removal/DryRemovalRuntimeEnvironment.php index 4cb8d1d42..6d1835e82 100644 --- a/setup/feature_removal/DryRemovalRuntimeEnvironment.php +++ b/setup/feature_removal/DryRemovalRuntimeEnvironment.php @@ -15,7 +15,7 @@ class DryRemovalRuntimeEnvironment extends RunTimeEnvironment * * @param string $sSourceEnv: environment from which setup is inspired to simulate extension removal and usee CompileFrom... */ - public function __construct($sSourceEnv = 'production', array $aExtensionCodesToRemove = []) + public function __construct($sSourceEnv = ITOP_DEFAULT_ENV, array $aExtensionCodesToRemove = []) { parent::__construct($sSourceEnv, false); $this->aExtensionsToRemoveByCode = $aExtensionCodesToRemove; diff --git a/setup/runtimeenv.class.inc.php b/setup/runtimeenv.class.inc.php index ec28de9b5..937631e52 100644 --- a/setup/runtimeenv.class.inc.php +++ b/setup/runtimeenv.class.inc.php @@ -396,9 +396,11 @@ class RunTimeEnvironment $sBuildConfigFile = APPCONF.$this->sBuildEnv.'/'.ITOP_CONFIG_FILE; // Write the config file - @chmod($sBuildConfigFile, 0770); // In case it exists: RWX for owner and group, nothing for others + if (is_file($sBuildConfigFile)) { + chmod($sBuildConfigFile, 0770); // In case it exists: RWX for owner and group, nothing for others + } $oConfig->WriteToFile($sBuildConfigFile); - @chmod($sBuildConfigFile, 0440); // Read-only for owner and group, nothing for others + chmod($sBuildConfigFile, 0440); // Read-only for owner and group, nothing for others } /** @@ -1331,11 +1333,12 @@ class RunTimeEnvironment public function DataToCleanupAudit() { - $oSetupAudit = new SetupAudit(ITOP_DEFAULT_ENV, $this->sBuildEnv); + $oSetupAudit = new SetupAudit($this->GetFinalEnv(), $this->GetBuildEnv()); //Make sure the MetaModel is started before analysing for issues - $sConfFile = utils::GetConfigFilePath(ITOP_DEFAULT_ENV); - MetaModel::Startup($sConfFile, false, false); // Start on production environment + $sFinalEnv = $this->GetFinalEnv(); + $sConfFile = utils::GetConfigFilePath($sFinalEnv); + MetaModel::Startup($sConfFile, false, false, false, $sFinalEnv); // Start on environment $oSetupAudit->RunDataAudit(true); $iCount = $oSetupAudit->GetDataToCleanupCount(); @@ -1350,15 +1353,11 @@ class RunTimeEnvironment $sDestinationEnv = $this->sBuildEnv; if ($sDestinationEnv != $sSourceEnv) { + if (file_exists(utils::GetDataPath().$sDestinationEnv.'.delta.xml')) { + unlink(utils::GetDataPath().$sDestinationEnv.'.delta.xml'); + } SetupUtils::CopyFile(utils::GetDataPath().$sSourceEnv.'.delta.xml', utils::GetDataPath().$sDestinationEnv.'.delta.xml'); SetupUtils::copydir(utils::GetDataPath().$sSourceEnv.'-modules/', utils::GetDataPath().$sDestinationEnv.'-modules/'); - - // Copy the config file - // - $sFinalConfig = APPCONF.$sDestinationEnv.'/config-itop.php'; - if (is_file($sFinalConfig)) { - chmod($sFinalConfig, 0770); // In case it exists: RWX for owner and group, nothing for others - } SetupUtils::copydir(APPCONF.$sSourceEnv, APPCONF.$sDestinationEnv); MetaModel::ResetAllCaches($sDestinationEnv); } @@ -1409,7 +1408,7 @@ class RunTimeEnvironment self::MakeDirSafe($sBuildDir); $bSkipTempDir = ($this->sFinalEnv != $this->sBuildEnv); // No need for a temporary directory if sBuildEnv is already a temporary directory $oMFCompiler = new MFCompiler($oFactory, $this->sFinalEnv); - $oMFCompiler->Compile($sBuildDir, null, $bUseSymLinks, $bSkipTempDir); + $oMFCompiler->Compile($sBuildDir, $bUseSymLinks, $bSkipTempDir); MetaModel::ResetAllCaches($this->sBuildEnv); @@ -1471,7 +1470,7 @@ class RunTimeEnvironment SetupUtils::tidydir($sBuildPath); } - $oExtensionsMap = new iTopExtensionsMap(ITOP_DEFAULT_ENV, $aDirsToScan); + $oExtensionsMap = new iTopExtensionsMap($this->GetFinalEnv(), $aDirsToScan); // Removed modules are stored as static for FindModules() $oExtensionsMap->DeclareExtensionAsRemoved($aRemovedExtensionCodes); @@ -1522,7 +1521,7 @@ class RunTimeEnvironment } $oMFCompiler = new MFCompiler($oFactory, $sEnvironment); - $oMFCompiler->Compile($sBuildPath, null, $bUseSymbolicLinks, false, false); + $oMFCompiler->Compile($sBuildPath, $bUseSymbolicLinks, false); SetupLog::Info("Data model successfully compiled to '$sBuildPath'."); $sCacheDir = APPROOT.'/data/cache-'.$sEnvironment.'/'; @@ -1572,7 +1571,7 @@ class RunTimeEnvironment public function EnterReadOnlyMode(Config $oConfig) { - if ($this->GetFinalEnv() != 'production') { + if ($this->GetFinalEnv() != ITOP_DEFAULT_ENV) { return; } @@ -1592,7 +1591,7 @@ class RunTimeEnvironment public function ExitReadOnlyMode() { - if ($this->GetFinalEnv() != 'production') { + if ($this->GetFinalEnv() != ITOP_DEFAULT_ENV) { return; } diff --git a/setup/sequencers/StepSequencer.php b/setup/sequencers/StepSequencer.php index 455c9aaea..58e9583e6 100644 --- a/setup/sequencers/StepSequencer.php +++ b/setup/sequencers/StepSequencer.php @@ -42,7 +42,7 @@ abstract class StepSequencer public function __construct(Parameters $oParams, ?RunTimeEnvironment $oRunTimeEnvironment = null, string $sSourceDesc = 'Setup') { if (is_null($oRunTimeEnvironment)) { - $sEnvironment = $oParams->Get('target_env', 'production'); + $sEnvironment = $oParams->Get('target_env', ITOP_DEFAULT_ENV); $this->oRunTimeEnvironment = new RunTimeEnvironment($sEnvironment, false); } else { $this->oRunTimeEnvironment = $oRunTimeEnvironment; @@ -171,12 +171,13 @@ abstract class StepSequencer protected function GetConfig() { if (! is_null($this->oTestConfig)) { + // For unit tests return $this->oTestConfig; } // Caching config here is a bad idea, the first config loaded does not contain module settings - $sTargetEnvironment = $this->oRunTimeEnvironment->GetBuildEnv(); - $sConfigFile = APPCONF.$sTargetEnvironment.'/'.ITOP_CONFIG_FILE; + $sBuildEnvironment = $this->oRunTimeEnvironment->GetBuildEnv(); + $sConfigFile = APPCONF.$sBuildEnvironment.'/'.ITOP_CONFIG_FILE; try { if (file_exists($sConfigFile)) { $oConfig = new Config($sConfigFile); diff --git a/setup/setuputils.class.inc.php b/setup/setuputils.class.inc.php index 776861168..91df4621f 100644 --- a/setup/setuputils.class.inc.php +++ b/setup/setuputils.class.inc.php @@ -527,11 +527,15 @@ class SetupUtils * * @since 3.0.0 N°2214 replace SetupLog::Log calls by CheckResult::TRACE */ - public static function CheckBackupPrerequisites($sDBBackupPath, $sMySQLBinDir = null) + public static function CheckBackupPrerequisites($sDBBackupPath, $sMySQLBinDir = null, string $sEnvironment = ITOP_DEFAULT_ENV) { $aResult = []; $aResult[] = new CheckResult(CheckResult::TRACE, 'Info - CheckBackupPrerequisites'); + if ($sEnvironment !== ITOP_DEFAULT_ENV) { + $aResult[] = new CheckResult(CheckResult::ERROR, "Can only backup ".ITOP_DEFAULT_ENV." environment"); + } + // zip extension // if (!extension_loaded('phar')) { @@ -1592,13 +1596,13 @@ JS if (is_dir($oWizard->GetParameter('copy_extensions_from'))) { $aDirsToScan[] = $oWizard->GetParameter('copy_extensions_from'); } - $sExtraDir = utils::GetDataPath().'production-modules/'; + $sExtraDir = utils::GetDataPath().$oWizard->GetParameter('target_env', ITOP_DEFAULT_ENV).'-modules/'; if (is_dir($sExtraDir)) { $aDirsToScan[] = $sExtraDir; } - $oProductionEnv = new RunTimeEnvironment(); + $oProductionEnv = new RunTimeEnvironment($oWizard->GetParameter('target_env', ITOP_DEFAULT_ENV)); $aRemovedExtensionCodes = json_decode($oWizard->GetParameter('removed_extensions'), true) ?? []; - $oExtensionsMap = new iTopExtensionsMap(ITOP_DEFAULT_ENV, $aDirsToScan); + $oExtensionsMap = new iTopExtensionsMap($oWizard->GetParameter('target_env', ITOP_DEFAULT_ENV), $aDirsToScan); $oExtensionsMap->DeclareExtensionAsRemoved($aRemovedExtensionCodes); $aAvailableModules = $oProductionEnv->AnalyzeInstallation($oConfig, $aDirsToScan, $bAbortOnMissingDependency, $aModulesToLoad); @@ -1615,9 +1619,12 @@ JS } /** + * Get version of production application + * * @param WizardController $oWizard * * @return array|bool + * @throws \CoreException */ public static function GetApplicationVersion($oWizard) { diff --git a/setup/unattended-install/InstallationFileService.php b/setup/unattended-install/InstallationFileService.php index 1b05151cf..655fc5635 100644 --- a/setup/unattended-install/InstallationFileService.php +++ b/setup/unattended-install/InstallationFileService.php @@ -56,7 +56,7 @@ class InstallationFileService public function GetProductionEnv(): RunTimeEnvironment { if (is_null($this->oProductionEnv)) { - $this->oProductionEnv = new RunTimeEnvironment(); + $this->oProductionEnv = new RunTimeEnvironment($this->sTargetEnvironment); } return $this->oProductionEnv; } @@ -258,8 +258,9 @@ class InstallationFileService public function ProcessDefaultModules(): void { $sProductionModuleDir = APPROOT.'data/'.$this->sTargetEnvironment.'-modules/'; + $oConfig = new Config(APPCONF.$this->sTargetEnvironment.'/'.ITOP_CONFIG_FILE); - $aAvailableModules = $this->GetProductionEnv()->AnalyzeInstallation(MetaModel::GetConfig(), $this->GetExtraDirs()); + $aAvailableModules = $this->GetProductionEnv()->AnalyzeInstallation($oConfig, $this->GetExtraDirs()); $this->aAutoSelectModules = []; foreach ($aAvailableModules as $sModuleId => $aModule) { diff --git a/setup/wizardsteps/AbstractWizStepInstall.php b/setup/wizardsteps/AbstractWizStepInstall.php index 60f39a6c1..c5dece5c9 100644 --- a/setup/wizardsteps/AbstractWizStepInstall.php +++ b/setup/wizardsteps/AbstractWizStepInstall.php @@ -73,7 +73,7 @@ abstract class AbstractWizStepInstall extends WizardStep 'datamodel_version' => $this->oWizard->GetParameter('datamodel_version'), //TODO: let the installer compute this automatically... 'previous_configuration_file' => $sPreviousConfigurationFile, 'extensions_dir' => $this->oWizard->GetParameter('extensions_dir', 'extensions'), - 'target_env' => 'production', + 'target_env' => $this->oWizard->GetParameter('target_env', ITOP_DEFAULT_ENV), 'workspace_dir' => '', 'database' => [ 'server' => $this->oWizard->GetParameter('db_server'), diff --git a/setup/wizardsteps/WizStepDataAudit.php b/setup/wizardsteps/WizStepDataAudit.php index 71c92f823..90ef5633d 100644 --- a/setup/wizardsteps/WizStepDataAudit.php +++ b/setup/wizardsteps/WizStepDataAudit.php @@ -102,17 +102,19 @@ JS); */ public function PostFormDisplay(SetupPage $oPage) { - $sApplicationUrl = utils::GetAbsoluteUrlModulePage('combodo-data-feature-removal', 'index.php'); + $sEnvironment = $this->oWizard->GetParameter('target_env', ITOP_DEFAULT_ENV); + $sApplicationUrl = utils::GetAbsoluteUrlModulePage('combodo-data-feature-removal', 'index.php', ['switch_env' => $sEnvironment], $sEnvironment); $aParams = [ 'selected_modules' => '[]', 'selected_extensions' => '[]', - 'display_choices' => '[]', + 'display_choices' => '', 'added_extensions' => '[]', 'removed_extensions' => '[]', 'extensions_not_uninstallable' => '[]', 'copy_setup_files' => 1, 'return_button_label' => '', + 'target_env' => ITOP_DEFAULT_ENV, 'force-uninstall' => "", 'use_symbolic_links' => "", ]; @@ -124,7 +126,6 @@ JS); INPUT; } - $sUID = Session::Get('setup_token'); $oPage->add( <<oWizard->GetParameter('target_env', ITOP_DEFAULT_ENV)); $oProductionEnv->InitDataModel($oConfig, true); $sIframeUrl = $oConfig->GetModuleSetting('itop-hub-connector', 'setup_url', ''); @@ -118,7 +119,8 @@ class WizStepDone extends WizardStep "); } - $sForm = '
'; + $sTargetEnv = utils::HtmlEntities($this->oWizard->GetParameter('target_env', ITOP_DEFAULT_ENV)); + $sForm = '
'; $sForm .= ''; $sForm .= ''; $sForm .= "
"; diff --git a/setup/wizardsteps/WizStepLandingBeforeAudit.php b/setup/wizardsteps/WizStepLandingBeforeAudit.php index 1c5317ea8..d318860a9 100644 --- a/setup/wizardsteps/WizStepLandingBeforeAudit.php +++ b/setup/wizardsteps/WizStepLandingBeforeAudit.php @@ -7,10 +7,12 @@ class WizStepLandingBeforeAudit extends WizStepModulesChoice { + private RunTimeEnvironment $oRuntimeEnv; + public function __construct(WizardController $oWizard, $sCurrentState) { - $oProductionEnv = new RunTimeEnvironment(); - $sBuildConfigFile = APPCONF.$oProductionEnv->GetBuildEnv().'/'.ITOP_CONFIG_FILE; + $this->oRuntimeEnv = new RunTimeEnvironment($oWizard->GetParameter('target_env', ITOP_DEFAULT_ENV)); + $sBuildConfigFile = APPCONF.$this->oRuntimeEnv->GetBuildEnv().'/'.ITOP_CONFIG_FILE; $this->oConfig = new Config($sBuildConfigFile); $oWizard->SetParameter('previous_version_dir', APPROOT); @@ -21,6 +23,19 @@ class WizStepLandingBeforeAudit extends WizStepModulesChoice $oWizard->SetParameter('datamodel_version', ITOP_CORE_VERSION); $oWizard->SetParameter('upgrade_type', 'use-compatible'); + $oWizard->SetParameter('db_server', $this->oConfig->Get('db_host')); + $oWizard->SetParameter('db_user', $this->oConfig->Get('db_user')); + $oWizard->SetParameter('db_pwd', $this->oConfig->Get('db_pwd')); + $oWizard->SetParameter('db_name', $this->oConfig->Get('db_name')); + $oWizard->SetParameter('db_prefix', $this->oConfig->Get('db_subname')); + $oWizard->SetParameter('db_tls_enabled', $this->oConfig->Get('db_tls.enabled')); + $oWizard->SetParameter('db_tls_ca', $this->oConfig->Get('db_tls.ca') ?? ''); + $oWizard->SetParameter('display_choices', ''); + $oWizard->SetParameter('extensions_not_uninstallable', '[]'); + + $oWizard->SaveParameter('use_symbolic_links', MFCompiler::UseSymbolicLinks()); + $oWizard->SaveParameter('force-uninstall', ''); + // should be done at the end parent::__construct($oWizard, $sCurrentState, false); } @@ -37,22 +52,10 @@ class WizStepLandingBeforeAudit extends WizStepModulesChoice */ public function UpdateWizardStateAndGetNextStep($bMoveForward = true): WizardState { - $oProductionEnv = new RunTimeEnvironment(); - $sBuildConfigFile = APPCONF.$oProductionEnv->GetBuildEnv().'/'.ITOP_CONFIG_FILE; + // Change the rights to production config file ! + $sBuildConfigFile = APPCONF.ITOP_DEFAULT_ENV.'/'.ITOP_CONFIG_FILE; @chmod($sBuildConfigFile, 0770); // In case it exists: RWX for owner and group, nothing for others - $oConfig = new Config($sBuildConfigFile); - $this->oWizard->SetParameter('db_server', $oConfig->Get('db_host')); - $this->oWizard->SetParameter('db_user', $oConfig->Get('db_user')); - $this->oWizard->SetParameter('db_pwd', $oConfig->Get('db_pwd')); - $this->oWizard->SetParameter('db_name', $oConfig->Get('db_name')); - $this->oWizard->SetParameter('db_prefix', $oConfig->Get('db_subname')); - $this->oWizard->SetParameter('db_tls_enabled', $oConfig->Get('db_tls.enabled')); - $this->oWizard->SetParameter('db_tls_ca', $oConfig->Get('db_tls.ca') ?? ''); - - $this->oWizard->SetParameter('display_choices', '[]'); - $this->oWizard->SetParameter('extensions_not_uninstallable', '[]'); - $aWizardSteps = $this->GetWizardSteps(); $this->oWizard->SetWizardSteps($aWizardSteps); $this->sCurrentState = count($aWizardSteps) - 1; @@ -60,6 +63,16 @@ class WizStepLandingBeforeAudit extends WizStepModulesChoice $aSelectedComponents = $this->GetSelectedComponents($this->aSteps, $this->oWizard->GetParameter('selected_extensions')); $this->oWizard->SetParameter('selected_components', json_encode($aSelectedComponents)); + // Save the choices for the summary step + $sDisplayChoices = '
    '; + $i = 0; + foreach ($this->aSteps as $aStepInfo) { + $sDisplayChoices .= $this->GetSelectedModules($aStepInfo, $aSelectedComponents[$i], $aModules, '', '', $aExtensions); + $i++; + } + $sDisplayChoices .= '
'; + $this->oWizard->SetParameter('display_choices', $sDisplayChoices); + return new WizardState(WizStepDataAudit::class); } diff --git a/setup/wizardsteps/WizStepModulesChoice.php b/setup/wizardsteps/WizStepModulesChoice.php index 28a2051bc..8914e4bed 100644 --- a/setup/wizardsteps/WizStepModulesChoice.php +++ b/setup/wizardsteps/WizStepModulesChoice.php @@ -58,10 +58,10 @@ class WizStepModulesChoice extends AbstractWizStepInstall $this->oExtensionsMap = new iTopExtensionsMap(); $sPreviousSourceDir = $this->oWizard->GetParameter('previous_version_dir', ''); $sConfigPath = null; - if (($sPreviousSourceDir !== '') && is_readable($sPreviousSourceDir.'/conf/production/config-itop.php')) { - $sConfigPath = $sPreviousSourceDir.'/conf/production/config-itop.php'; - } elseif (is_readable(utils::GetConfigFilePath(ITOP_DEFAULT_ENV))) { - $sConfigPath = utils::GetConfigFilePath(ITOP_DEFAULT_ENV); + if (($sPreviousSourceDir !== '') && is_readable($sPreviousSourceDir.'/conf/'.ITOP_DEFAULT_ENV.'/config-itop.php')) { + $sConfigPath = $sPreviousSourceDir.'/conf/'.ITOP_DEFAULT_ENV.'/config-itop.php'; + } elseif (is_readable(utils::GetConfigFilePath($this->oWizard->GetParameter('target_env', ITOP_DEFAULT_ENV)))) { + $sConfigPath = utils::GetConfigFilePath($this->oWizard->GetParameter('target_env', ITOP_DEFAULT_ENV)); } // only called if the config file exists : we are updating a previous installation !