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();
}
/**