From 32ef639ce1f7712b0a3652e612550c8a44815654 Mon Sep 17 00:00:00 2001 From: Eric Espie Date: Mon, 16 Dec 2024 16:44:59 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B07803=20-=20MTP=20from=20itophub/designer?= =?UTF-8?q?=20failing=20in=20itop=203.2.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/utils.inc.php | 7 +++-- core/metamodel.class.php | 33 ++++++++++++++++++++++++ setup/applicationinstaller.class.inc.php | 2 +- setup/runtimeenv.class.inc.php | 10 +++---- setup/setuputils.class.inc.php | 11 ++++---- 5 files changed, 48 insertions(+), 15 deletions(-) diff --git a/application/utils.inc.php b/application/utils.inc.php index 41bf97c6d..922f967af 100644 --- a/application/utils.inc.php +++ b/application/utils.inc.php @@ -1451,9 +1451,12 @@ class utils * @return string A path to a folder into which any module can store cache data * The corresponding folder is created or cleaned upon code compilation */ - public static function GetCachePath() + public static function GetCachePath(string $sEnvironment = null): string { - return static::GetDataPath().'cache-'.MetaModel::GetEnvironment().'/'; + if (is_null($sEnvironment)) { + $sEnvironment = MetaModel::GetEnvironment(); + } + return static::GetDataPath()."cache-$sEnvironment/"; } /** diff --git a/core/metamodel.class.php b/core/metamodel.class.php index 08a503065..f0195fc3d 100644 --- a/core/metamodel.class.php +++ b/core/metamodel.class.php @@ -7532,8 +7532,41 @@ abstract class MetaModel return $aEntries; } + public static function ResetAllCaches($sEnvironment = null) + { + if (is_null($sEnvironment)) { + $sEnvironment = MetaModel::GetEnvironment(); + } + + $sEnvironmentId = md5(APPROOT).'-'.$sEnvironment; + $sAppIdentity = 'itop-'.$sEnvironmentId; + require_once(APPROOT.'/core/dict.class.inc.php'); + Dict::ResetCache($sAppIdentity); + + if (function_exists('apc_delete')) { + foreach (self::GetCacheEntries($sEnvironmentId) as $sKey => $aAPCInfo) { + $sAPCKey = $aAPCInfo['info']; + apc_delete($sAPCKey); + } + } + + require_once(APPROOT.'core/userrights.class.inc.php'); + UserRights::FlushPrivileges(); + + // Reset the opcache since otherwise the PHP "model" files may still be cached !! + if (function_exists('opcache_reset')) { + // Zend opcode cache + opcache_reset(); + } + + require_once(APPROOT.'setup/setuputils.class.inc.php'); + SetupUtils::rrmdir(utils::GetCachePath($sEnvironment)); + } + /** + * @internal * @param string $sEnvironmentId + * @deprecated 3.2.1 */ public static function ResetCache($sEnvironmentId = null) { diff --git a/setup/applicationinstaller.class.inc.php b/setup/applicationinstaller.class.inc.php index a3662fcb3..754846884 100644 --- a/setup/applicationinstaller.class.inc.php +++ b/setup/applicationinstaller.class.inc.php @@ -1089,7 +1089,7 @@ class ApplicationInstaller // Ready to go !! require_once(APPROOT.'core/dict.class.inc.php'); - MetaModel::ResetCache(); + MetaModel::ResetAllCaches(); } } diff --git a/setup/runtimeenv.class.inc.php b/setup/runtimeenv.class.inc.php index 2d551450d..ea4f3f3e0 100644 --- a/setup/runtimeenv.class.inc.php +++ b/setup/runtimeenv.class.inc.php @@ -125,7 +125,7 @@ class RunTimeEnvironment if (!$bUseCache) { // Reset the cache for the first use ! - MetaModel::ResetCache(md5(APPROOT).'-'.$this->sTargetEnv); + MetaModel::ResetAllCaches($this->sTargetEnv); } MetaModel::Startup($oConfig, $bModelOnly, $bUseCache, false /* $bTraceSourceFiles */, $this->sTargetEnv); @@ -534,11 +534,7 @@ class RunTimeEnvironment $oMFCompiler = new MFCompiler($oFactory, $this->sFinalEnv); $oMFCompiler->Compile($sTargetDir, null, $bUseSymLinks, $bSkipTempDir); - $sCacheDir = APPROOT.'data/cache-'.$this->sTargetEnv; - SetupUtils::builddir($sCacheDir); - SetupUtils::tidydir($sCacheDir); - - MetaModel::ResetCache(md5(APPROOT).'-'.$this->sTargetEnv); + MetaModel::ResetAllCaches($this->sTargetEnv); return array_keys($aModulesToCompile); } @@ -994,7 +990,7 @@ class RunTimeEnvironment @chmod($sFinalConfig, 0440); // Read-only for owner and group, nothing for others @rmdir(dirname($sTargetConfig)); // Cleanup the temporary build dir if empty - MetaModel::ResetCache(md5(APPROOT).'-'.$this->sFinalEnv); + MetaModel::ResetAllCaches($this->sFinalEnv); } } diff --git a/setup/setuputils.class.inc.php b/setup/setuputils.class.inc.php index 9d2d8ecb9..2301752b5 100644 --- a/setup/setuputils.class.inc.php +++ b/setup/setuputils.class.inc.php @@ -790,15 +790,16 @@ class SetupUtils // avoid unnecessary warning // Try 100 times... $i = 100; - while ((@rmdir($dir) === false) && $i > 0) - { + while ((@rmdir($dir) === false) && $i > 0) { // Magic trick for windows // sometimes the folder is empty but rmdir fails - closedir(opendir($dir)); + $oDir = opendir($dir); + if ($oDir !== false) { + closedir($oDir); + } $i--; } - if ($i == 0) - { + if ($i == 0) { rmdir($dir); } }