N°4280 Handle modules with non existing model.*.php files imported (#295)

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
This commit is contained in:
Pierre Goiffon
2022-06-15 17:20:13 +02:00
committed by GitHub
parent 8890940b06
commit 023ead39ec
2 changed files with 24 additions and 2 deletions

View File

@@ -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)

View File

@@ -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;