From 4cfeae9ca03fcbc721445a18754da478ea81f9a0 Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Wed, 12 Sep 2012 13:28:49 +0000 Subject: [PATCH] Adaptations to potentially run the setup from the CLI SVN:trunk[2178] --- core/config.class.inc.php | 9 ++++--- core/metamodel.class.php | 52 ++++++++++++++++++++++----------------- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/core/config.class.inc.php b/core/config.class.inc.php index deb4abd7a..914fd9c9f 100644 --- a/core/config.class.inc.php +++ b/core/config.class.inc.php @@ -708,10 +708,12 @@ class Config $this->Verify(); } - // Application root url: set a default value, then normalize it - $sAppRootUrl = trim($this->Get('app_root_url')); + // Application root url: set a default value, then normalize it +/* + * Does not work in CLI/unattended mode + $sAppRootUrl = trim($this->Get('app_root_url')); if (strlen($sAppRootUrl) == 0) - { + { $sAppRootUrl = utils::GetDefaultUrlAppRoot(); } if (substr($sAppRootUrl, -1, 1) != '/') @@ -719,6 +721,7 @@ class Config $sAppRootUrl .= '/'; } $this->Set('app_root_url', $sAppRootUrl); + */ } protected function CheckFile($sPurpose, $sFileName) diff --git a/core/metamodel.class.php b/core/metamodel.class.php index b6299f24c..6c3626d1e 100644 --- a/core/metamodel.class.php +++ b/core/metamodel.class.php @@ -4283,22 +4283,25 @@ abstract class MetaModel public static function Startup($config, $bModelOnly = false, $bAllowCache = true, $bTraceSourceFiles = false) { - define('MODULESROOT', APPROOT.'env-'.utils::GetCurrentEnvironment().'/'); - - self::$m_bTraceSourceFiles = $bTraceSourceFiles; - - // $config can be either a filename, or a Configuration object (volatile!) - if ($config instanceof Config) + if (!defined('MODULESROOT')) { - self::LoadConfig($config, $bAllowCache); + define('MODULESROOT', APPROOT.'env-'.utils::GetCurrentEnvironment().'/'); + + self::$m_bTraceSourceFiles = $bTraceSourceFiles; + + // $config can be either a filename, or a Configuration object (volatile!) + if ($config instanceof Config) + { + self::LoadConfig($config, $bAllowCache); + } + else + { + self::LoadConfig(new Config($config), $bAllowCache); + } + + if ($bModelOnly) return; } - else - { - self::LoadConfig(new Config($config), $bAllowCache); - } - - if ($bModelOnly) return; - + CMDBSource::SelectDB(self::$m_sDBName); foreach(get_declared_classes() as $sPHPClass) @@ -4949,17 +4952,20 @@ abstract class MetaModel { $sEnvironment = MetaModel::GetEnvironmentId(); } - $aCacheUserData = apc_cache_info('user'); - $sPrefix = 'itop-'.$sEnvironment.'-'; - $aEntries = array(); - foreach($aCacheUserData['cache_list'] as $i => $aEntry) - { - $sEntryKey = $aEntry['info']; - if (strpos($sEntryKey, $sPrefix) === 0) + $aCacheUserData = @apc_cache_info('user'); + if (is_array($aCacheUserData)) + { + $sPrefix = 'itop-'.$sEnvironment.'-'; + + foreach($aCacheUserData['cache_list'] as $i => $aEntry) { - $sCleanKey = substr($sEntryKey, strlen($sPrefix)); - $aEntries[$sCleanKey] = $aEntry; + $sEntryKey = $aEntry['info']; + if (strpos($sEntryKey, $sPrefix) === 0) + { + $sCleanKey = substr($sEntryKey, strlen($sPrefix)); + $aEntries[$sCleanKey] = $aEntry; + } } } return $aEntries;