2
0
forked from Wavyzz/dolibarr

Merge branch '20.0' of git@github.com:Dolibarr/dolibarr.git into 21.0

This commit is contained in:
Laurent Destailleur (aka Eldy)
2025-01-20 15:02:37 +01:00
32 changed files with 568 additions and 29 deletions

View File

@@ -10512,10 +10512,11 @@ 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<-1,max>|string ID of code if OK, 0 if key empty, -1 if KO
* @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 $conf;
@@ -10525,7 +10526,7 @@ function dol_getIdFromCode($db, $key, $tablename, $fieldkey = 'code', $fieldid =
}
// Check in cache
if (isset($conf->cache['codeid'][$tablename][$key][$fieldid])) { // Can be defined to 0 or ''
if ($useCache && isset($conf->cache['codeid'][$tablename][$key][$fieldid])) { // Can be defined to 0 or ''
return $conf->cache['codeid'][$tablename][$key][$fieldid]; // Found in cache
}
@@ -10548,14 +10549,16 @@ function dol_getIdFromCode($db, $key, $tablename, $fieldkey = 'code', $fieldid =
$resql = $db->query($sql);
if ($resql) {
$obj = $db->fetch_object($resql);
$valuetoget = '';
if ($obj) {
$conf->cache['codeid'][$tablename][$key][$fieldid] = $obj->valuetoget;
$valuetoget = $obj->valuetoget;
$conf->cache['codeid'][$tablename][$key][$fieldid] = $valuetoget;
} else {
$conf->cache['codeid'][$tablename][$key][$fieldid] = '';
}
$db->free($resql);
return $conf->cache['codeid'][$tablename][$key][$fieldid];
return $valuetoget;
} else {
return -1;
}