diff --git a/application/utils.inc.php b/application/utils.inc.php
index b4bea9bf9..e2e7571a3 100644
--- a/application/utils.inc.php
+++ b/application/utils.inc.php
@@ -76,6 +76,12 @@ class FileUploadException extends Exception
*/
class utils
{
+ /**
+ * Cache when getting config from disk or set externally (using {@link SetConfig})
+ * @internal
+ * @var Config $oConfig
+ * @see GetConfig
+ */
private static $oConfig = null;
// Parameters loaded from a file, parameters of the page/command line still have precedence
@@ -707,31 +713,58 @@ class utils
}
/**
- * @return \Config from the current environement, or if not existing from the production env, else new Config made from scratch
- * @uses \MetaModel::GetConfig() don't forget to add the needed require_once(APPROOT.'core/metamodel.class.php');
+ * @param \Config $oConfig
+ *
*/
- static public function GetConfig()
+ public static function SetConfig(Config $oConfig)
{
- if (self::$oConfig == null)
+ self::$oConfig = $oConfig;
+ }
+
+ /**
+ * @return \Config Get object in the following order :
+ *
+ * - from {@link MetaModel::GetConfig} if loaded
+ *
- {@link oConfig} attribute if set
+ *
- from disk (current env, using {@link GetConfigFilePath}) => if loaded this will be stored in {@link oConfig} attribute
+ *
- from disk, env production => if loaded this will be stored in {@link oConfig} attribute
+ *
- default Config object
+ *
+ * @throws \ConfigException
+ * @throws \CoreException
+ *
+ * @since 2.7.0 N°2478 always call {@link MetaModel::GetConfig} first, cache is only set when loading from disk
+ */
+ public static function GetConfig()
+ {
+ $oMetaModelConfig = MetaModel::GetConfig();
+ if ($oMetaModelConfig !== null)
{
- self::$oConfig = MetaModel::GetConfig();
-
- if (self::$oConfig == null)
- {
- $sConfigFile = self::GetConfigFilePath();
- if (!file_exists($sConfigFile))
- {
- $sConfigFile = self::GetConfigFilePath('production');
- if (!file_exists($sConfigFile))
- {
- $sConfigFile = null;
- }
- }
-
- self::$oConfig = new Config($sConfigFile);
- }
+ return $oMetaModelConfig;
}
- return self::$oConfig;
+
+ if (self::$oConfig !== null)
+ {
+ return self::$oConfig;
+ }
+
+ $sCurrentEnvConfigPath = self::GetConfigFilePath();
+ if (file_exists($sCurrentEnvConfigPath))
+ {
+ $oCurrentEnvDiskConfig = new Config($sCurrentEnvConfigPath);
+ self::$oConfig = $oCurrentEnvDiskConfig;
+ return self::$oConfig;
+ }
+
+ $sProductionEnvConfigPath = self::GetConfigFilePath('production');
+ if (file_exists($sProductionEnvConfigPath))
+ {
+ $oProductionEnvDiskConfig = new Config($sProductionEnvConfigPath);
+ self::$oConfig = $oProductionEnvDiskConfig;
+ return self::$oConfig;
+ }
+
+ return new Config();
}
public static function InitTimeZone() {
diff --git a/setup/applicationinstaller.class.inc.php b/setup/applicationinstaller.class.inc.php
index eeaa7083d..534089784 100644
--- a/setup/applicationinstaller.class.inc.php
+++ b/setup/applicationinstaller.class.inc.php
@@ -41,15 +41,50 @@ class ApplicationInstaller
const WARNING = 3;
const INFO = 4;
- /** @var \PHPParameters */
+ /** @var \Parameters */
protected $oParams;
protected static $bMetaModelStarted = false;
-
+
+ /**
+ * @param \Parameters $oParams
+ *
+ * @throws \ConfigException
+ * @throws \CoreException
+ */
public function __construct($oParams)
{
$this->oParams = $oParams;
+
+ $aParamValues = $oParams->GetParamForConfigArray();
+ $oConfig = new Config();
+ $sTargetDir = $this->GetTargetDir();
+ $oConfig->UpdateFromParams($aParamValues, $sTargetDir);
+ utils::SetConfig($oConfig);
}
-
+
+ /**
+ * @return string
+ */
+ private function GetTargetEnv()
+ {
+ $sTargetEnvironment = $this->oParams->Get('target_env', '');
+ if ($sTargetEnvironment !== '')
+ {
+ return $sTargetEnvironment;
+ }
+
+ return 'production';
+ }
+
+ /**
+ * @return string
+ */
+ private function GetTargetDir()
+ {
+ $sTargetEnv = $this->GetTargetEnv();
+ return 'env-'.$sTargetEnv;
+ }
+
/**
* Runs all the installation steps in one go and directly outputs
* some information about the progress and the success of the various
@@ -180,7 +215,7 @@ class ApplicationInstaller
// __DB__-%Y-%m-%d
$sDestination = $aPreinstall['backup']['destination'];
$sSourceConfigFile = $aPreinstall['backup']['configuration_file'];
- $aDBParams = $this->GetParamValues($this->oParams);
+ $aDBParams = $this->oParams->GetParamForConfigArray();
$oTempConfig = new Config();
$oTempConfig->UpdateFromParams($aDBParams);
$sMySQLBinDir = $this->oParams->Get('mysql_bindir', null);
@@ -199,12 +234,8 @@ class ApplicationInstaller
$aSelectedModules = $this->oParams->Get('selected_modules');
$sSourceDir = $this->oParams->Get('source_dir', 'datamodels/latest');
$sExtensionDir = $this->oParams->Get('extensions_dir', 'extensions');
- $sTargetEnvironment = $this->oParams->Get('target_env', '');
- if ($sTargetEnvironment == '')
- {
- $sTargetEnvironment = 'production';
- }
- $sTargetDir = 'env-'.$sTargetEnvironment;
+ $sTargetEnvironment = $this->GetTargetEnv();
+ $sTargetDir = $this->GetTargetDir();
$bUseSymbolicLinks = false;
$aMiscOptions = $this->oParams->Get('options', array());
if (isset($aMiscOptions['symlinks']) && $aMiscOptions['symlinks'])
@@ -234,13 +265,9 @@ class ApplicationInstaller
case 'db-schema':
$aSelectedModules = $this->oParams->Get('selected_modules', array());
- $sTargetEnvironment = $this->oParams->Get('target_env', '');
- if ($sTargetEnvironment == '')
- {
- $sTargetEnvironment = 'production';
- }
- $sTargetDir = 'env-'.$sTargetEnvironment;
- $aParamValues = $this->GetParamValues($this->oParams);
+ $sTargetEnvironment = $this->GetTargetEnv();
+ $sTargetDir = $this->GetTargetDir();
+ $aParamValues = $this->oParams->GetParamForConfigArray();
$bOldAddon = $this->oParams->Get('old_addon', false);
$sUrl = $this->oParams->Get('url', '');
@@ -257,13 +284,9 @@ class ApplicationInstaller
break;
case 'after-db-create':
- $sTargetEnvironment = $this->oParams->Get('target_env', '');
- if ($sTargetEnvironment == '')
- {
- $sTargetEnvironment = 'production';
- }
- $sTargetDir = 'env-'.$sTargetEnvironment;
- $aParamValues = $this->GetParamValues($this->oParams);
+ $sTargetEnvironment = $this->GetTargetEnv();
+ $sTargetDir = $this->GetTargetDir();
+ $aParamValues = $this->oParams->GetParamForConfigArray();
$aAdminParams = $this->oParams->Get('admin_account');
$sAdminUser = $aAdminParams['user'];
$sAdminPwd = $aAdminParams['pwd'];
@@ -285,9 +308,9 @@ class ApplicationInstaller
case 'load-data':
$aSelectedModules = $this->oParams->Get('selected_modules');
- $sTargetEnvironment = $this->oParams->Get('target_env', '');
- $sTargetDir = 'env-'.(($sTargetEnvironment == '') ? 'production' : $sTargetEnvironment);
- $aParamValues = $this->GetParamValues($this->oParams);
+ $sTargetEnvironment = $this->GetTargetEnv();
+ $sTargetDir = $this->GetTargetDir();
+ $aParamValues = $this->oParams->GetParamForConfigArray();
$bOldAddon = $this->oParams->Get('old_addon', false);
$bSampleData = ($this->oParams->Get('sample_data', 0) == 1);
@@ -304,19 +327,14 @@ class ApplicationInstaller
break;
case 'create-config':
- $sTargetEnvironment = $this->oParams->Get('target_env', '');
- if ($sTargetEnvironment == '')
- {
- $sTargetEnvironment = 'production';
- }
-
- $sTargetDir = 'env-'.$sTargetEnvironment;
+ $sTargetEnvironment = $this->GetTargetEnv();
+ $sTargetDir = $this->GetTargetDir();
$sPreviousConfigFile = $this->oParams->Get('previous_configuration_file', '');
$sDataModelVersion = $this->oParams->Get('datamodel_version', '0.0.0');
$bOldAddon = $this->oParams->Get('old_addon', false);
$aSelectedModuleCodes = $this->oParams->Get('selected_modules', array());
$aSelectedExtensionCodes = $this->oParams->Get('selected_extensions', array());
- $aParamValues = $this->GetParamValues($this->oParams);
+ $aParamValues = $this->oParams->GetParamForConfigArray();
self::DoCreateConfig($sTargetDir, $sPreviousConfigFile, $sTargetEnvironment, $sDataModelVersion,
$bOldAddon, $aSelectedModuleCodes, $aSelectedExtensionCodes, $aParamValues);
@@ -376,33 +394,6 @@ class ApplicationInstaller
return $aResult;
}
- /**
- * @param array $oParams
- *
- * @return array to use with {@see Config::UpdateFromParams}
- */
- private function GetParamValues($oParams)
- {
- $aDBParams = $oParams->Get('database');
- $aParamValues = array(
- 'mode' => $oParams->Get('mode'),
- 'db_server' => $aDBParams['server'],
- 'db_user' => $aDBParams['user'],
- 'db_pwd' => $aDBParams['pwd'],
- 'db_name' => $aDBParams['name'],
- 'new_db_name' => $aDBParams['name'],
- 'db_prefix' => $aDBParams['prefix'],
- 'db_tls_enabled' => $aDBParams['db_tls_enabled'],
- 'db_tls_ca' => $aDBParams['db_tls_ca'],
- 'application_path' => $oParams->Get('url', ''),
- 'language' => $oParams->Get('language', ''),
- 'graphviz_path' => $oParams->Get('graphviz_path', ''),
- 'source_dir' => $oParams->Get('source_dir', ''),
- );
-
- return $aParamValues;
- }
-
protected static function DoCopy($aCopies)
{
$aReports = array();
diff --git a/setup/parameters.class.inc.php b/setup/parameters.class.inc.php
index 6e237069a..48600c550 100644
--- a/setup/parameters.class.inc.php
+++ b/setup/parameters.class.inc.php
@@ -20,7 +20,32 @@ abstract class Parameters
}
return $default;
}
-
+
+ /**
+ * @return array to use with {@see Config::UpdateFromParams}
+ */
+ public function GetParamForConfigArray()
+ {
+ $aDBParams = $this->Get('database');
+ $aParamValues = array(
+ 'mode' => $this->Get('mode'),
+ 'db_server' => $aDBParams['server'],
+ 'db_user' => $aDBParams['user'],
+ 'db_pwd' => $aDBParams['pwd'],
+ 'db_name' => $aDBParams['name'],
+ 'new_db_name' => $aDBParams['name'],
+ 'db_prefix' => $aDBParams['prefix'],
+ 'db_tls_enabled' => $aDBParams['db_tls_enabled'],
+ 'db_tls_ca' => $aDBParams['db_tls_ca'],
+ 'application_path' => $this->Get('url', ''),
+ 'language' => $this->Get('language', ''),
+ 'graphviz_path' => $this->Get('graphviz_path', ''),
+ 'source_dir' => $this->Get('source_dir', ''),
+ );
+
+ return $aParamValues;
+ }
+
protected function Set($sCode, $value)
{
$this->aData[$sCode] = $value;
@@ -200,4 +225,5 @@ class XMLParameters extends Parameters
}
return $sRet;
}
+
}
diff --git a/setup/runtimeenv.class.inc.php b/setup/runtimeenv.class.inc.php
index 3196c358d..01a72db1c 100644
--- a/setup/runtimeenv.class.inc.php
+++ b/setup/runtimeenv.class.inc.php
@@ -24,11 +24,10 @@
* @license http://opensource.org/licenses/AGPL-3.0
*/
-require_once(APPROOT."setup/modulediscovery.class.inc.php");
-require_once(APPROOT.'setup/modelfactory.class.inc.php');
-require_once(APPROOT.'setup/compiler.class.inc.php');
-require_once(APPROOT.'setup/extensionsmap.class.inc.php');
-require_once(APPROOT.'core/metamodel.class.php');
+require_once APPROOT."setup/modulediscovery.class.inc.php";
+require_once APPROOT.'setup/modelfactory.class.inc.php';
+require_once APPROOT.'setup/compiler.class.inc.php';
+require_once APPROOT.'setup/extensionsmap.class.inc.php';
define ('MODULE_ACTION_OPTIONAL', 1);
define ('MODULE_ACTION_MANDATORY', 2);
@@ -111,26 +110,8 @@ class RunTimeEnvironment
*/
public function InitDataModel($oConfig, $bModelOnly = true, $bUseCache = false)
{
- require_once(APPROOT.'/core/log.class.inc.php');
- require_once(APPROOT.'/core/kpi.class.inc.php');
- require_once(APPROOT.'/core/coreexception.class.inc.php');
- require_once(APPROOT.'/core/dict.class.inc.php');
- require_once(APPROOT.'/core/attributedef.class.inc.php');
- require_once(APPROOT.'/core/filterdef.class.inc.php');
- require_once(APPROOT.'/core/stimulus.class.inc.php');
- require_once(APPROOT.'/core/MyHelpers.class.inc.php');
- require_once(APPROOT.'/core/oql/expression.class.inc.php');
- require_once(APPROOT.'/core/cmdbsource.class.inc.php');
- require_once(APPROOT.'/core/sqlquery.class.inc.php');
- require_once(APPROOT.'/core/sqlobjectquery.class.inc.php');
- require_once(APPROOT.'/core/sqlunionquery.class.inc.php');
- require_once(APPROOT.'/core/dbobject.class.php');
- require_once(APPROOT.'/core/dbsearch.class.php');
- require_once(APPROOT.'/core/dbobjectset.class.php');
- require_once(APPROOT.'/application/cmdbabstract.class.inc.php');
- require_once(APPROOT.'/core/userrights.class.inc.php');
- require_once(APPROOT.'/setup/moduleinstallation.class.inc.php');
-
+ require_once APPROOT.'/setup/moduleinstallation.class.inc.php';
+
$sConfigFile = $oConfig->GetLoadedFile();
if (strlen($sConfigFile) > 0)
{
@@ -243,7 +224,6 @@ class RunTimeEnvironment
try
{
- require_once(APPROOT.'/core/cmdbsource.class.inc.php');
CMDBSource::InitFromConfig($oConfig);
$aSelectInstall = CMDBSource::QueryToArray("SELECT * FROM ".$oConfig->Get('db_subname')."priv_module_install");
}
@@ -818,7 +798,6 @@ class RunTimeEnvironment
$aResult = false;
try
{
- require_once(APPROOT.'/core/cmdbsource.class.inc.php');
CMDBSource::InitFromConfig($oConfig);
$sSQLQuery = "SELECT * FROM ".$oConfig->Get('db_subname')."priv_module_install";
$aSelectInstall = CMDBSource::QueryToArray($sSQLQuery);