From 09b12bd06ed5e37155a8fca536d17e59621edae3 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Mon, 3 May 2021 16:56:33 +0200 Subject: [PATCH] :art: Add check to prevent setup crash when creating config In a4782942 a !empty() test was added but this was useless The problem that was causing the issue was an undefined index when doing $aAvailableModules[$sModuleId] --- setup/runtimeenv.class.inc.php | 73 +++++++++++++++++----------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/setup/runtimeenv.class.inc.php b/setup/runtimeenv.class.inc.php index 7c9142d1b..30535086e 100644 --- a/setup/runtimeenv.class.inc.php +++ b/setup/runtimeenv.class.inc.php @@ -735,48 +735,49 @@ class RunTimeEnvironment $oInstallRec->Set('parent_id', 0); // root module $oInstallRec->Set('installed', $iInstallationTime); $iMainItopRecord = $oInstallRec->DBInsertNoReload(); - - + + // Record installed modules and extensions // $aAvailableExtensions = array(); $aAvailableModules = $this->AnalyzeInstallation($oConfig, $this->GetBuildDir()); - if (!empty($aSelectedModuleCodes)) { - foreach ($aSelectedModuleCodes as $sModuleId) { - $aModuleData = $aAvailableModules[$sModuleId]; - $sName = $sModuleId; - $sVersion = $aModuleData['version_code']; - $aComments = array(); - $aComments[] = $sShortComment; - if ($aModuleData['mandatory']) { - $aComments[] = 'Mandatory'; - } else { - $aComments[] = 'Optional'; - } - if ($aModuleData['visible']) { - $aComments[] = 'Visible (during the setup)'; - } else { - $aComments[] = 'Hidden (selected automatically)'; - } - - $aDependencies = $aModuleData['dependencies']; - if (!empty($aDependencies)) { - foreach ($aDependencies as $sDependOn) { - $aComments[] = "Depends on module: $sDependOn"; - } - } - $sComment = implode("\n", $aComments); - - $oInstallRec = new ModuleInstallation(); - $oInstallRec->Set('name', $sName); - $oInstallRec->Set('version', $sVersion); - $oInstallRec->Set('comment', $sComment); - $oInstallRec->Set('parent_id', $iMainItopRecord); - $oInstallRec->Set('installed', $iInstallationTime); - $oInstallRec->DBInsertNoReload(); + foreach ($aSelectedModuleCodes as $sModuleId) { + if (!array_key_exists($sModuleId, $aAvailableModules)) { + continue; } + $aModuleData = $aAvailableModules[$sModuleId]; + $sName = $sModuleId; + $sVersion = $aModuleData['version_code']; + $aComments = array(); + $aComments[] = $sShortComment; + if ($aModuleData['mandatory']) { + $aComments[] = 'Mandatory'; + } else { + $aComments[] = 'Optional'; + } + if ($aModuleData['visible']) { + $aComments[] = 'Visible (during the setup)'; + } else { + $aComments[] = 'Hidden (selected automatically)'; + } + + $aDependencies = $aModuleData['dependencies']; + if (!empty($aDependencies)) { + foreach ($aDependencies as $sDependOn) { + $aComments[] = "Depends on module: $sDependOn"; + } + } + $sComment = implode("\n", $aComments); + + $oInstallRec = new ModuleInstallation(); + $oInstallRec->Set('name', $sName); + $oInstallRec->Set('version', $sVersion); + $oInstallRec->Set('comment', $sComment); + $oInstallRec->Set('parent_id', $iMainItopRecord); + $oInstallRec->Set('installed', $iInstallationTime); + $oInstallRec->DBInsertNoReload(); } - + if ($this->oExtensionsMap) { // Mark as chosen the selected extensions code passed to us