mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-15 22:11:36 +01:00
FIX 17.0 - collisions in cache for dol_getIdFromCode
This commit is contained in:
@@ -8876,12 +8876,13 @@ function dol_osencode($str)
|
||||
* @param string $fieldid Field to get
|
||||
* @param int $entityfilter Filter by entity
|
||||
* @param string $filters Filters to add. WARNING: string must be escaped for SQL and not coming from user input.
|
||||
* @param bool $useCache If true (default), cache will be queried and updated.
|
||||
* @return int <0 if KO, Id of code if OK
|
||||
* @see $langs->getLabelFromKey
|
||||
*/
|
||||
function dol_getIdFromCode($db, $key, $tablename, $fieldkey = 'code', $fieldid = 'id', $entityfilter = 0, $filters = '')
|
||||
function dol_getIdFromCode($db, $key, $tablename, $fieldkey = 'code', $fieldid = 'id', $entityfilter = 0, $filters = '', $useCache = true)
|
||||
{
|
||||
global $cache_codes;
|
||||
static $cache_codes = array();
|
||||
|
||||
// If key empty
|
||||
if ($key == '') {
|
||||
@@ -8889,8 +8890,8 @@ function dol_getIdFromCode($db, $key, $tablename, $fieldkey = 'code', $fieldid =
|
||||
}
|
||||
|
||||
// Check in cache
|
||||
if (isset($cache_codes[$tablename][$key][$fieldid])) { // Can be defined to 0 or ''
|
||||
return $cache_codes[$tablename][$key][$fieldid]; // Found in cache
|
||||
if ($useCache && isset($cache_codes[$tablename][$fieldkey][$fieldid][$entityfilter][$filters][$key])) { // Can be defined to 0 or ''
|
||||
return $cache_codes[$tablename][$fieldkey][$fieldid][$entityfilter][$filters][$key]; // Found in cache
|
||||
}
|
||||
|
||||
dol_syslog('dol_getIdFromCode (value for field '.$fieldid.' from key '.$key.' not found into cache)', LOG_DEBUG);
|
||||
@@ -8908,13 +8909,15 @@ function dol_getIdFromCode($db, $key, $tablename, $fieldkey = 'code', $fieldid =
|
||||
$resql = $db->query($sql);
|
||||
if ($resql) {
|
||||
$obj = $db->fetch_object($resql);
|
||||
$valuetoget = '';
|
||||
if ($obj) {
|
||||
$cache_codes[$tablename][$key][$fieldid] = $obj->valuetoget;
|
||||
} else {
|
||||
$cache_codes[$tablename][$key][$fieldid] = '';
|
||||
$valuetoget = $obj->valuetoget;
|
||||
}
|
||||
$db->free($resql);
|
||||
return $cache_codes[$tablename][$key][$fieldid];
|
||||
if ($useCache) {
|
||||
$cache_codes[$tablename][$fieldkey][$fieldid][$entityfilter][$filters][$key] = $valuetoget;
|
||||
}
|
||||
return $valuetoget;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
@@ -10839,21 +10842,21 @@ function dolGetStatus($statusLabel = '', $statusLabelShort = '', $html = '', $st
|
||||
* @param int|boolean $userRight User action right
|
||||
* // phpcs:disable
|
||||
* @param array $params = [ // Various params for future : recommended rather than adding more function arguments
|
||||
* 'attr' => [ // to add or override button attributes
|
||||
* 'xxxxx' => '', // your xxxxx attribute you want
|
||||
* 'class' => 'reposition', // to add more css class to the button class attribute
|
||||
* 'classOverride' => '' // to replace class attribute of the button
|
||||
* ],
|
||||
* 'confirm' => [
|
||||
* 'url' => 'http://', // Overide Url to go when user click on action btn, if empty default url is $url.?confirm=yes, for no js compatibility use $url for fallback confirm.
|
||||
* 'title' => '', // Overide title of modal, if empty default title use "ConfirmBtnCommonTitle" lang key
|
||||
* 'action-btn-label' => '', // Overide label of action button, if empty default label use "Confirm" lang key
|
||||
* 'cancel-btn-label' => '', // Overide label of cancel button, if empty default label use "CloseDialog" lang key
|
||||
* 'content' => '', // Overide text of content, if empty default content use "ConfirmBtnCommonContent" lang key
|
||||
* 'modal' => true, // true|false to display dialog as a modal (with dark background)
|
||||
* 'isDropDrown' => false, // true|false to display dialog as a dropdown (with dark background)
|
||||
* ],
|
||||
* ]
|
||||
* 'attr' => [ // to add or override button attributes
|
||||
* 'xxxxx' => '', // your xxxxx attribute you want
|
||||
* 'class' => 'reposition', // to add more css class to the button class attribute
|
||||
* 'classOverride' => '' // to replace class attribute of the button
|
||||
* ],
|
||||
* 'confirm' => [
|
||||
* 'url' => 'http://', // Overide Url to go when user click on action btn, if empty default url is $url.?confirm=yes, for no js compatibility use $url for fallback confirm.
|
||||
* 'title' => '', // Overide title of modal, if empty default title use "ConfirmBtnCommonTitle" lang key
|
||||
* 'action-btn-label' => '', // Overide label of action button, if empty default label use "Confirm" lang key
|
||||
* 'cancel-btn-label' => '', // Overide label of cancel button, if empty default label use "CloseDialog" lang key
|
||||
* 'content' => '', // Overide text of content, if empty default content use "ConfirmBtnCommonContent" lang key
|
||||
* 'modal' => true, // true|false to display dialog as a modal (with dark background)
|
||||
* 'isDropDrown' => false, // true|false to display dialog as a dropdown (with dark background)
|
||||
* ],
|
||||
* ]
|
||||
* // phpcs:enable
|
||||
* @return string html button
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user