From 057fcdfaef2158ee240c8d99b5d5cac122722f02 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 13 Sep 2024 18:44:23 +0200 Subject: [PATCH] Fix: In v20, all global caches must use $conf->cache['nameofcache'] instead of a global variable. --- htdocs/core/lib/functions.lib.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index f8621e2bbd2..11fedc5ef0b 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -12963,7 +12963,7 @@ function getElementProperties($elementType) */ function fetchObjectByElement($element_id, $element_type, $element_ref = '', $useCache = 0, $maxCacheByType = 10) { - global $db, $globalCacheForGetObjectFromCache; + global $db, $conf; $ret = 0; @@ -12985,11 +12985,11 @@ function fetchObjectByElement($element_id, $element_type, $element_ref = '', $us //var_dump($element_prop['module'].' '.$ismodenabled); if (is_array($element_prop) && (empty($element_prop['module']) || $ismodenabled)) { if ($useCache === 1 - && !empty($globalCacheForGetObjectFromCache[$element_type]) - && !empty($globalCacheForGetObjectFromCache[$element_type][$element_id]) - && is_object($globalCacheForGetObjectFromCache[$element_type][$element_id]) + && !empty($conf->cache['fetchObjectByElement'][$element_type]) + && !empty($conf->cache['fetchObjectByElement'][$element_type][$element_id]) + && is_object($conf->cache['fetchObjectByElement'][$element_type][$element_id]) ) { - return $globalCacheForGetObjectFromCache[$element_type][$element_id]; + return $conf->cache['fetchObjectByElement'][$element_type][$element_id]; } dol_include_once('/'.$element_prop['classpath'].'/'.$element_prop['classfile'].'.class.php'); @@ -13007,16 +13007,16 @@ function fetchObjectByElement($element_id, $element_type, $element_ref = '', $us } if ($useCache > 0) { - if (!isset($globalCacheForGetObjectFromCache[$element_type])) { - $globalCacheForGetObjectFromCache[$element_type] = []; + if (!isset($conf->cache['fetchObjectByElement'][$element_type])) { + $conf->cache['fetchObjectByElement'][$element_type] = []; } // Manage cache limit - if (! empty($globalCacheForGetObjectFromCache[$element_type]) && is_array($globalCacheForGetObjectFromCache[$element_type]) && count($globalCacheForGetObjectFromCache[$element_type]) >= $maxCacheByType) { - array_shift($globalCacheForGetObjectFromCache[$element_type]); + if (! empty($conf->cache['fetchObjectByElement'][$element_type]) && is_array($conf->cache['fetchObjectByElement'][$element_type]) && count($conf->cache['fetchObjectByElement'][$element_type]) >= $maxCacheByType) { + array_shift($conf->cache['fetchObjectByElement'][$element_type]); } - $globalCacheForGetObjectFromCache[$element_type][$element_id] = $objecttmp; + $conf->cache['fetchObjectByElement'][$element_type][$element_id] = $objecttmp; } return $objecttmp;