diff --git a/setup/runtimeenv.class.inc.php b/setup/runtimeenv.class.inc.php index 75d5df9491..e94126962c 100644 --- a/setup/runtimeenv.class.inc.php +++ b/setup/runtimeenv.class.inc.php @@ -465,93 +465,12 @@ class RunTimeEnvironment } /** - * Get the installed modules (only the installed ones) + * Getadditional modules to compiljust before delta * @return \MFModule[] */ - protected function GetMFModulesToCompile($sSourceEnv, $sSourceDir): array + protected function GetAdditionalMFModulesBeforeFinalDeltaToCompile(string $sSourceEnv, array $aScannedModulesRootDirs): array { - list($aExtraDirs, $aDirsToCompile) = $this->GetDirsToCompile($sSourceDir); - $oSourceConfig = new Config(APPCONF.$sSourceEnv.'/'.ITOP_CONFIG_FILE); - $this->InitExtensionMap($aExtraDirs, $oSourceConfig); - $this->GetExtensionMap()->LoadChoicesFromDatabase($oSourceConfig); - foreach ($this->GetExtensionMap()->GetAllExtensions() as $oExtension) { - if ($this->IsExtensionSelected($oExtension)) { - $this->GetExtensionMap()->MarkAsChosen($oExtension->sCode); - } - } - $aModulesToLoad = $this->GetModulesToLoad($this->sFinalEnv, $aDirsToCompile); - foreach ($aModulesToLoad as $sKey) { - if (false !== strpos($sKey, 'enduser')) { - SetupLog::Error(__METHOD__.':'.__LINE__.' aModulesToLoad: '.$sKey) ; - } - } - $aAvailableModules = $this->AnalyzeInstallation($oSourceConfig, $aDirsToCompile, true, $aModulesToLoad); - - // Do load the required modules - $oDictModule = new MFDictModule('dictionaries', 'iTop Dictionaries', APPROOT.'dictionaries'); - - $aRet = []; - $aRet[$oDictModule->GetName()] = $oDictModule; - - $oFactory = new ModelFactory($aDirsToCompile); - $sDeltaFile = APPROOT.'core/datamodel.core.xml'; - if (file_exists($sDeltaFile)) { - $oCoreModule = new MFCoreModule('core', 'Core Module', $sDeltaFile); - $aRet[$oCoreModule->GetName()] = $oCoreModule; - } - $sDeltaFile = APPROOT.'application/datamodel.application.xml'; - if (file_exists($sDeltaFile)) { - $oApplicationModule = new MFCoreModule('application', 'Application Module', $sDeltaFile); - $aRet[$oApplicationModule->GetName()] = $oApplicationModule; - } - - $aModules = $oFactory->FindModules(); - foreach ($aModules as $oModule) { - $sModule = $oModule->GetName(); - - if (false !== strpos($sModule, 'enduser')) { - SetupLog::Error(__METHOD__.':'.__LINE__.' oFactory->FindModules: '.$sModule) ; - } - $bIsExtra = $this->GetExtensionMap()->ModuleIsChosenAsPartOfAnExtension($sModule, iTopExtension::SOURCE_REMOTE); - if (array_key_exists($sModule, $aAvailableModules)) { - if (($aAvailableModules[$sModule]['installed_version'] != '') || $bIsExtra && !$oModule->IsAutoSelect()) { //Extra modules are always unless they are 'AutoSelect' - $aRet[$oModule->GetName()] = $oModule; - } - } - } - - $oPhpExpressionEvaluator = new PhpExpressionEvaluator([], ModuleFileReader::STATIC_CALL_AUTOSELECT_WHITELIST); - - // Now process the 'AutoSelect' modules - do { - // Loop while new modules are added... - $bModuleAdded = false; - foreach ($aModules as $oModule) { - if (!array_key_exists($oModule->GetName(), $aRet) && $oModule->IsAutoSelect()) { - if (false !== strpos($oModule->GetName(), 'enduser')) { - SetupLog::Error(__METHOD__.':'.__LINE__.' IsAutoSelect: '.$oModule->GetName()) ; - } - SetupInfo::SetSelectedModules($aRet); - try { - $bSelected = $oPhpExpressionEvaluator->ParseAndEvaluateBooleanExpression($oModule->GetAutoSelect()); - if ($bSelected) { - $aRet[$oModule->GetName()] = $oModule; // store the Id of the selected module - $bModuleAdded = true; - } - } catch (ModuleFileReaderException $e) { - //do nothing. logged already - } - } - } - } while ($bModuleAdded); - - $sDeltaFile = utils::GetDataPath().$this->sBuildEnv.'.delta.xml'; - if (file_exists($sDeltaFile)) { - $oDelta = new MFDeltaModule($sDeltaFile); - $aRet[$oDelta->GetName()] = $oDelta; - } - - return $aRet; + return []; } /** @@ -1398,44 +1317,6 @@ class RunTimeEnvironment $aSelectedExtensions = $this->GetExtensionMap()->GetSelectedExtensions($oConfig, [], []); $aSelectedModules = $this->GetModulesToLoadFromChoices($oConfig, $aSelectedExtensions, $this->GetExtensionMap()->GetScannedModulesRootDirs()); return $this->DoCompile(array_keys($aSelectedExtensions), [], $aSelectedModules, $bUseSymLinks ?? false); - - /* - - $oSourceConfig = new Config(utils::GetConfigFilePath($sSourceEnv)); - $sSourceDir = $oSourceConfig->Get('source_dir'); - - $sSourceDirFull = APPROOT.$sSourceDir; - // Do load the required modules - // - $oFactory = new ModelFactory($sSourceDirFull); - $aModulesToCompile = $this->GetMFModulesToCompile($sSourceEnv, $sSourceDir); - $oModule = null; - foreach ($aModulesToCompile as $oModule) { - if ($oModule instanceof MFDeltaModule) { - // Just before loading the delta, let's save an image of the datamodel - // in case there is no delta the operation will be done after the end of the loop - $oFactory->SaveToFile(utils::GetDataPath().'datamodel-'.$this->sBuildEnv.'.xml'); - } - $oFactory->LoadModule($oModule); - } - - if (!is_null($oModule) && ($oModule instanceof MFDeltaModule)) { - // A delta was loaded, let's save a second copy of the datamodel - $oFactory->SaveToFile(utils::GetDataPath().'datamodel-'.$this->sBuildEnv.'-with-delta.xml'); - } else { - // No delta was loaded, let's save the datamodel now - $oFactory->SaveToFile(utils::GetDataPath().'datamodel-'.$this->sBuildEnv.'.xml'); - } - - $sBuildDir = APPROOT.'env-'.$this->sBuildEnv; - self::MakeDirSafe($sBuildDir); - $bSkipTempDir = ($this->sFinalEnv != $this->sBuildEnv); // No need for a temporary directory if sBuildEnv is already a temporary directory - $oMFCompiler = new MFCompiler($oFactory, $this->sFinalEnv); - $oMFCompiler->Compile($sBuildDir, $bUseSymLinks, $bSkipTempDir); - - MetaModel::ResetAllCaches($this->sBuildEnv); - - return array_keys($aModulesToCompile);*/ } /** @@ -1529,7 +1410,6 @@ class RunTimeEnvironment } $aModules = $oFactory->FindModules(); - foreach ($aModules as $oModule) { $sModule = $oModule->GetName(); if (in_array($sModule, $aSelectedModules)) { @@ -1537,6 +1417,11 @@ class RunTimeEnvironment } } + $aModulesToCompile = $this->GetAdditionalMFModulesBeforeFinalDeltaToCompile($sEnvironment, $oExtensionsMap->GetScannedModulesRootDirs()); + foreach ($aModulesToCompile as $oModule) { + $oFactory->LoadModule($oModule); + } + // Dump the "reference" model, just before loading any actual delta $oFactory->SaveToFile(utils::GetDataPath().'datamodel-'.$sEnvironment.'.xml'); diff --git a/tests/php-unit-tests/src/Service/UnitTestRunTimeEnvironment.php b/tests/php-unit-tests/src/Service/UnitTestRunTimeEnvironment.php index 72d6c2cbf1..f6417ff741 100644 --- a/tests/php-unit-tests/src/Service/UnitTestRunTimeEnvironment.php +++ b/tests/php-unit-tests/src/Service/UnitTestRunTimeEnvironment.php @@ -108,11 +108,9 @@ class UnitTestRunTimeEnvironment extends RunTimeEnvironment /** * @inheritDoc */ - protected function GetMFModulesToCompile($sSourceEnv, $sSourceDir): array + protected function GetAdditionalMFModulesBeforeFinalDeltaToCompile(string $sSourceEnv, array $aScannedModulesRootDirs): array { \SetupLog::Info(__METHOD__); - $aRet = parent::GetMFModulesToCompile($sSourceEnv, $sSourceDir); - if ($this->bUseDelta) { foreach ($this->GetCustomDatamodelFiles() as $sDeltaFile) { $sDeltaId = preg_replace('/[^\d\w]/', '', $sDeltaFile); diff --git a/tests/php-unit-tests/unitary-tests/datamodels/2.x/combodo-data-feature-removal/DataCleanupServiceTest.php b/tests/php-unit-tests/unitary-tests/datamodels/2.x/combodo-data-feature-removal/DataCleanupServiceTest.php index 0d3d04062c..cbf3b54f2e 100644 --- a/tests/php-unit-tests/unitary-tests/datamodels/2.x/combodo-data-feature-removal/DataCleanupServiceTest.php +++ b/tests/php-unit-tests/unitary-tests/datamodels/2.x/combodo-data-feature-removal/DataCleanupServiceTest.php @@ -15,6 +15,8 @@ use Combodo\iTop\Test\UnitTest\ItopCustomDatamodelTestCase; use Combodo\iTop\Test\UnitTest\ItopDataTestCase; use PHPUnit\Framework\MockObject\MockObject; +require_once __DIR__."/AbstractCleanup.php"; + /** * Unit tests for the CleanupService cf the Combodo Data Feature Removal module. * diff --git a/tests/php-unit-tests/unitary-tests/datamodels/2.x/combodo-data-feature-removal/StaticDeletionPlanTest.php b/tests/php-unit-tests/unitary-tests/datamodels/2.x/combodo-data-feature-removal/StaticDeletionPlanTest.php index 643974c95f..bd0e00a470 100644 --- a/tests/php-unit-tests/unitary-tests/datamodels/2.x/combodo-data-feature-removal/StaticDeletionPlanTest.php +++ b/tests/php-unit-tests/unitary-tests/datamodels/2.x/combodo-data-feature-removal/StaticDeletionPlanTest.php @@ -11,6 +11,7 @@ use Combodo\iTop\DataFeatureRemoval\Entity\DataCleanupSummaryEntity; use Combodo\iTop\DataFeatureRemoval\Service\StaticDeletionPlan; use MetaModel; +require_once __DIR__."/AbstractCleanup.php"; class StaticDeletionPlanTest extends \AbstractCleanup { public function GetDatamodelDeltaAbsPath(): string