From 0cc28b42b2b019e24a62a6c0429b10da7739d29b Mon Sep 17 00:00:00 2001 From: Eric Espie Date: Tue, 16 May 2023 10:22:53 +0200 Subject: [PATCH] :white_check_mark: Move EventService init to Metamodel::Startup() for unit tests --- application/startup.inc.php | 6 ----- core/metamodel.class.php | 52 ++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/application/startup.inc.php b/application/startup.inc.php index af4824a83..f5c2b54ba 100644 --- a/application/startup.inc.php +++ b/application/startup.inc.php @@ -15,10 +15,7 @@ // // You should have received a copy of the GNU Affero General Public License // along with iTop. If not, see -use Combodo\iTop\Application\EventRegister\ApplicationEvents; use Combodo\iTop\Application\Helper\Session; -use Combodo\iTop\Service\Events\EventData; -use Combodo\iTop\Service\Events\EventService; require_once(APPROOT.'core/cmdbobject.class.inc.php'); require_once(APPROOT.'application/utils.inc.php'); @@ -103,6 +100,3 @@ else } $sConfigFile = APPCONF.$sEnv.'/'.ITOP_CONFIG_FILE; MetaModel::Startup($sConfigFile, false /* $bModelOnly */, $bAllowCache, false /* $bTraceSourceFiles */, $sEnv); -// Event service must be initialized after the MetaModel startup, otherwise it cannot discover classes implementing the iEventServiceSetup interface -EventService::InitService(); -EventService::FireEvent(new EventData(ApplicationEvents::APPLICATION_EVENT_METAMODEL_STARTED)); diff --git a/core/metamodel.class.php b/core/metamodel.class.php index d3b531e2f..66606ab69 100644 --- a/core/metamodel.class.php +++ b/core/metamodel.class.php @@ -17,7 +17,10 @@ // along with iTop. If not, see // +use Combodo\iTop\Application\EventRegister\ApplicationEvents; use Combodo\iTop\Core\MetaModel\FriendlyNameType; +use Combodo\iTop\Service\Events\EventData; +use Combodo\iTop\Service\Events\EventService; require_once APPROOT.'core/modulehandler.class.inc.php'; require_once APPROOT.'core/querymodifier.class.inc.php'; @@ -6343,36 +6346,37 @@ abstract class MetaModel { self::$m_sEnvironment = $sEnvironment; - if (!defined('MODULESROOT')) - { - define('MODULESROOT', APPROOT.'env-'.self::$m_sEnvironment.'/'); + try { + if (!defined('MODULESROOT')) { + define('MODULESROOT', APPROOT.'env-'.self::$m_sEnvironment.'/'); - self::$m_bTraceSourceFiles = $bTraceSourceFiles; + 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); + // $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; + } } - if ($bModelOnly) - { - return; + CMDBSource::SelectDB(self::$m_sDBName); + + foreach (MetaModel::EnumPlugins('ModuleHandlerApiInterface') as $oPHPClass) { + $oPHPClass::OnMetaModelStarted(); } + + ExpressionCache::Warmup(); + } + finally { + // Event service must be initialized after the MetaModel startup, otherwise it cannot discover classes implementing the iEventServiceSetup interface + EventService::InitService(); + EventService::FireEvent(new EventData(ApplicationEvents::APPLICATION_EVENT_METAMODEL_STARTED)); } - - CMDBSource::SelectDB(self::$m_sDBName); - - foreach(MetaModel::EnumPlugins('ModuleHandlerApiInterface') as $oPHPClass) - { - $oPHPClass::OnMetaModelStarted(); - } - - ExpressionCache::Warmup(); } /**