From 023ead39ecdf11b032dae3d47ee27f7375a9dac2 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Wed, 15 Jun 2022 17:20:13 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B04280=20Handle=20modules=20with=20non=20e?= =?UTF-8?q?xisting=20model.*.php=20files=20imported=20(#295)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We were crashing iTop when having a module with : * in the 'datamodel' key in the module.*.php file a 'model.*.php' declared * no model.*.php file in the module sources * no model.*.php generated after compilation This behavior is improved : * if isdevenv an exception will be thrown detailing which module is concerned * else : - model.*.php won't be added in iTop datamodel autoload - a SetupLog::Error will be made --- setup/compiler.class.inc.php | 16 +++++++++++++++- setup/modelfactory.class.inc.php | 10 +++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/setup/compiler.class.inc.php b/setup/compiler.class.inc.php index 61c883c68..574d15ab0 100644 --- a/setup/compiler.class.inc.php +++ b/setup/compiler.class.inc.php @@ -617,7 +617,21 @@ EOF; // files to include (PHP datamodels) foreach($oModule->GetFilesToInclude('business') as $sRelFileName) { - $aDataModelFiles[] = "MetaModel::IncludeModule(MODULESROOT.'/$sRelativeDir/$sRelFileName');"; + if (file_exists("{$sTempTargetDir}/{$sRelativeDir}/{$sRelFileName}")) { + $aDataModelFiles[] = "MetaModel::IncludeModule(MODULESROOT.'/$sRelativeDir/$sRelFileName');"; + } else { + /** @noinspection NestedPositiveIfStatementsInspection */ + if (utils::IsDevelopmentEnvironment()) { + $sMissingBusinessFileMessage = 'A module embeds a non existing file : check the module.php "datamodel" key !'; + $aContext = [ + 'moduleId' => $oModule->GetId(), + 'moduleLocation' => $oModule->GetRootDir(), + 'includedFile' => $sRelFileName, + ]; + SetupLog::Error($sMissingBusinessFileMessage, null, $aContext); + throw new CoreException($sMissingBusinessFileMessage, $aContext); + } + } } // files to include (PHP webservices providers) foreach($oModule->GetFilesToInclude('webservices') as $sRelFileName) diff --git a/setup/modelfactory.class.inc.php b/setup/modelfactory.class.inc.php index 603e337f2..9d5eb6787 100644 --- a/setup/modelfactory.class.inc.php +++ b/setup/modelfactory.class.inc.php @@ -139,7 +139,15 @@ class MFModule */ protected $sAutoSelect; /** - * @var array + * @see ModelFactory::FindModules init of this structure from the module.*.php files + * @var array{ + * business: string[], + * webservices: string[], + * addons: string[], + * } + * Warning, there are naming mismatches between this structure and the module.*.php : + * - `business` here correspond to `datamodel` in module.*.php + * - `webservices` here correspond to `webservice` in module.*.php */ protected $aFilesToInclude;