Skip to content

Commit

Permalink
FIX 17.0 - collisions in cache for dol_getIdFromCode
Browse files Browse the repository at this point in the history
  • Loading branch information
atm-florianm committed Jan 10, 2025
1 parent 6388f6e commit 77f982d
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions htdocs/core/lib/functions.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -8876,21 +8876,22 @@ 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 == '') {
return '';
}

// 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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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.

Check failure on line 10851 in htdocs/core/lib/functions.lib.php

View workflow job for this annotation

GitHub Actions / pre-commit

Overide ==> Override
* 'title' => '', // Overide title of modal, if empty default title use "ConfirmBtnCommonTitle" lang key

Check failure on line 10852 in htdocs/core/lib/functions.lib.php

View workflow job for this annotation

GitHub Actions / pre-commit

Overide ==> Override
* 'action-btn-label' => '', // Overide label of action button, if empty default label use "Confirm" lang key

Check failure on line 10853 in htdocs/core/lib/functions.lib.php

View workflow job for this annotation

GitHub Actions / pre-commit

Overide ==> Override
* 'cancel-btn-label' => '', // Overide label of cancel button, if empty default label use "CloseDialog" lang key

Check failure on line 10854 in htdocs/core/lib/functions.lib.php

View workflow job for this annotation

GitHub Actions / pre-commit

Overide ==> Override
* 'content' => '', // Overide text of content, if empty default content use "ConfirmBtnCommonContent" lang key

Check failure on line 10855 in htdocs/core/lib/functions.lib.php

View workflow job for this annotation

GitHub Actions / pre-commit

Overide ==> Override
* '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
*/
Expand Down

0 comments on commit 77f982d

Please sign in to comment.