mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°2013 Setup : fix crash on setting readonly mode if initial DB info were wrong
Same as 15d3201a, but this error happened before compilation, when setting read only mode.
As before this is another fix for #351.
This fix introduces the new method \WizardController::GetParamForConfigArray
I replaced existing duplicate code with a call to this new generic method.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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('<iframe id="fresh_content" frameborder="0" scrolling="auto" src="'.$sIframeUrl.'"></iframe>');
|
||||
|
||||
$oPage->add_script("
|
||||
|
||||
Reference in New Issue
Block a user