diff --git a/core/config.class.inc.php b/core/config.class.inc.php index b6997cdc4..5b782b7ce 100644 --- a/core/config.class.inc.php +++ b/core/config.class.inc.php @@ -2469,11 +2469,14 @@ class Config /** * Helper function to initialize a configuration from the page arguments * + * @see \Parameters::GetParamForConfigArray() to get aParamValues from {@see Parameters} object hierarchy in setup + * @see \WizardController::GetParamForConfigArray() to get aParamValues from {@see \WizardController} object hierarchy in setup + * * @param array $aParamValues - * @param string|null $sModulesDir + * @param ?string $sModulesDir * @param bool $bPreserveModuleSettings * - * @return void + * @return void The current object is modified directly * * @throws \Exception * @throws \CoreException diff --git a/setup/applicationinstaller.class.inc.php b/setup/applicationinstaller.class.inc.php index 19284686b..3057e2622 100644 --- a/setup/applicationinstaller.class.inc.php +++ b/setup/applicationinstaller.class.inc.php @@ -165,14 +165,17 @@ class ApplicationInstaller { $sTargetEnvironment = $this->GetTargetEnv(); $sConfigFile = APPCONF.$sTargetEnvironment.'/'.ITOP_CONFIG_FILE; - try - { - return new Config($sConfigFile); + try { + $oConfig = new Config($sConfigFile); } - catch (Exception $e) - { + catch (Exception $e) { return null; } + + $aParamValues = $this->oParams->GetParamForConfigArray(); + $oConfig->UpdateFromParams($aParamValues); + + return $oConfig; } /** diff --git a/setup/parameters.class.inc.php b/setup/parameters.class.inc.php index 7d3d94904..0bc938250 100644 --- a/setup/parameters.class.inc.php +++ b/setup/parameters.class.inc.php @@ -22,7 +22,7 @@ abstract class Parameters } /** - * @return array to use with {@see Config::UpdateFromParams} + * @return array Allow to update config using {@see Config::UpdateFromParams()} */ public function GetParamForConfigArray() { diff --git a/setup/setuputils.class.inc.php b/setup/setuputils.class.inc.php index 6682eb65f..938f0d6b3 100644 --- a/setup/setuputils.class.inc.php +++ b/setup/setuputils.class.inc.php @@ -1547,8 +1547,7 @@ JS } /** - * - * @param $oWizard + * @param \WizardController $oWizard * @param bool $bAbortOnMissingDependency ... * @param array $aModulesToLoad List of modules to search for, defaults to all if ommitted * @@ -1561,39 +1560,23 @@ JS $oConfig = new Config(); $sSourceDir = $oWizard->GetParameter('source_dir', ''); - if (strpos($sSourceDir, APPROOT) !== false) - { + if (strpos($sSourceDir, APPROOT) !== false) { $sRelativeSourceDir = str_replace(APPROOT, '', $sSourceDir); - } - else if (strpos($sSourceDir, $oWizard->GetParameter('previous_version_dir')) !== false) - { + } else if (strpos($sSourceDir, $oWizard->GetParameter('previous_version_dir')) !== false) { $sRelativeSourceDir = str_replace($oWizard->GetParameter('previous_version_dir'), '', $sSourceDir); - } - else - { + } else { throw(new Exception('Internal error: AnalyzeInstallation: source_dir is neither under APPROOT nor under previous_installation_dir ???')); } - - $aParamValues = array( - 'db_server' => $oWizard->GetParameter('db_server', ''), - 'db_user' => $oWizard->GetParameter('db_user', ''), - 'db_pwd' => $oWizard->GetParameter('db_pwd', ''), - 'db_name' => $oWizard->GetParameter('db_name', ''), - 'db_prefix' => $oWizard->GetParameter('db_prefix', ''), - 'db_tls_enabled' => $oWizard->GetParameter('db_tls_enabled', false), - 'db_tls_ca' => $oWizard->GetParameter('db_tls_ca', ''), - 'source_dir' => $sRelativeSourceDir, - ); + $aParamValues = $oWizard->GetParamForConfigArray(); + $aParamValues['source_dir'] = $sRelativeSourceDir; $oConfig->UpdateFromParams($aParamValues, null); $aDirsToScan = array($sSourceDir); - if (is_dir(APPROOT.'extensions')) - { + if (is_dir(APPROOT.'extensions')) { $aDirsToScan[] = APPROOT.'extensions'; } - if (is_dir($oWizard->GetParameter('copy_extensions_from'))) - { + if (is_dir($oWizard->GetParameter('copy_extensions_from'))) { $aDirsToScan[] = $oWizard->GetParameter('copy_extensions_from'); } $sExtraDir = APPROOT.'data/production-modules/'; @@ -1627,16 +1610,8 @@ JS require_once(APPROOT.'/setup/moduleinstaller.class.inc.php'); $oConfig = new Config(); - $aParamValues = array( - 'db_server' => $oWizard->GetParameter('db_server', ''), - 'db_user' => $oWizard->GetParameter('db_user', ''), - 'db_pwd' => $oWizard->GetParameter('db_pwd', ''), - 'db_name' => $oWizard->GetParameter('db_name', ''), - 'db_prefix' => $oWizard->GetParameter('db_prefix', ''), - 'db_tls_enabled' => $oWizard->GetParameter('db_tls_enabled', false), - 'db_tls_ca' => $oWizard->GetParameter('db_tls_ca', ''), - 'source_dir' => '', - ); + $aParamValues = $oWizard->GetParamForConfigArray(); + $aParamValues['source_dir'] = ''; $oConfig->UpdateFromParams($aParamValues, null); $oProductionEnv = new RunTimeEnvironment(); diff --git a/setup/wizardcontroller.class.inc.php b/setup/wizardcontroller.class.inc.php index ca4664323..6cbcfaec0 100644 --- a/setup/wizardcontroller.class.inc.php +++ b/setup/wizardcontroller.class.inc.php @@ -75,15 +75,37 @@ class WizardController */ public function GetParameter($sParamCode, $defaultValue = '') { - if (array_key_exists($sParamCode, $this->aParameters)) - { + if (array_key_exists($sParamCode, $this->aParameters)) { return $this->aParameters[$sParamCode]; } + return $defaultValue; } + /** + * @return array Allow to update config using {@see Config::UpdateFromParams()} + * + * @since 3.1.0 N°2013 + */ + public function GetParamForConfigArray(): array + { + /** @noinspection PhpUnnecessaryLocalVariableInspection */ + $aParamValues = array( + 'db_server' => $this->GetParameter('db_server', ''), + 'db_user' => $this->GetParameter('db_user', ''), + 'db_pwd' => $this->GetParameter('db_pwd', ''), + 'db_name' => $this->GetParameter('db_name', ''), + 'db_prefix' => $this->GetParameter('db_prefix', ''), + 'db_tls_enabled' => $this->GetParameter('db_tls_enabled', false), + 'db_tls_ca' => $this->GetParameter('db_tls_ca', ''), + ); + + return $aParamValues; + } + /** * Stores a "persistent" parameter in the wizard's context + * * @param string $sParamCode The code identifying this parameter * @param mixed $value The value to store */ diff --git a/setup/wizardsteps.class.inc.php b/setup/wizardsteps.class.inc.php index 6cb3313e4..696ce5970 100644 --- a/setup/wizardsteps.class.inc.php +++ b/setup/wizardsteps.class.inc.php @@ -1337,15 +1337,7 @@ class WizStepModulesChoice extends WizardStep { $oConfig = new Config($sConfigPath); - $aParamValues = array( - 'db_server' => $oWizard->GetParameter('db_server', ''), - 'db_user' => $oWizard->GetParameter('db_user', ''), - 'db_pwd' => $oWizard->GetParameter('db_pwd', ''), - 'db_name' => $oWizard->GetParameter('db_name', ''), - 'db_prefix' => $oWizard->GetParameter('db_prefix', ''), - 'db_tls_enabled' => $oWizard->GetParameter('db_tls_enabled', false), - 'db_tls_ca' => $oWizard->GetParameter('db_tls_ca', ''), - ); + $aParamValues = $oWizard->GetParamForConfigArray(); $oConfig->UpdateFromParams($aParamValues); $this->bChoicesFromDatabase = $this->oExtensionsMap->LoadChoicesFromDatabase($oConfig); @@ -2588,6 +2580,8 @@ class WizStepDone extends WizardStep $oConfig = new Config(utils::GetConfigFilePath()); + $aParamValues = $this->oWizard->GetParamForConfigArray(); + $oConfig->UpdateFromParams($aParamValues); // Load the data model only, in order to load env-production/core/main.php to get the XML parameters (needed by GetModuleSettings below) // But main.php may also contain classes (defined without any module), and thus requiring the full data model // to be loaded to prevent "class not found" errors... @@ -2595,8 +2589,7 @@ class WizStepDone extends WizardStep $oProductionEnv->InitDataModel($oConfig, true); $sIframeUrl = $oConfig->GetModuleSetting('itop-hub-connector', 'setup_url', ''); - if ($sIframeUrl != '') - { + if ($sIframeUrl != '') { $oPage->add(''); $oPage->add_script("