From e9e526c0320561d7f8d1e403fd064be331c978ea Mon Sep 17 00:00:00 2001 From: Jam Balaya Date: Sun, 19 Jul 2026 22:45:45 +0900 Subject: [PATCH 01/14] FIX #35658 leading-zero account numbers dropped from personalized group totals (#39208) In compta/resultat/result.php and clientfourn.php the account number was cast to (int) before being passed to AccountancyCategory::getSumDebitCredit(), which compares it as a string (t.numero_compte = '...'). (int) '0510' -> 510 -> '510' never matches the stored '0510' (numero_compte and account_number are varchar(32), so leading zeros are significant). Accounts whose code starts with 0 were therefore silently excluded from the current-year and per-month totals of a personalized account group, while the previous-year column was already correct because it passes a string array. The (int) cast had no functional purpose: it was added to silence a phan notice in "Qual: Fix phan notices" (#33484). Remove it and pass the raw string, and widen the getSumDebitCredit() @param to string|int|array so the string argument is accepted by static analysis and the cast is not reintroduced. Numeric codes are unaffected (the callee already casts the scalar with (string)). --- htdocs/accountancy/class/accountancycategory.class.php | 2 +- htdocs/compta/resultat/clientfourn.php | 2 +- htdocs/compta/resultat/result.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/accountancy/class/accountancycategory.class.php b/htdocs/accountancy/class/accountancycategory.class.php index 2c0d985e41e..0f028eb8781 100644 --- a/htdocs/accountancy/class/accountancycategory.class.php +++ b/htdocs/accountancy/class/accountancycategory.class.php @@ -624,7 +624,7 @@ class AccountancyCategory // extends CommonObject /** * Function to set the property ->sdc (and ->sdcperaccount) that is the result of an accounting account from the ledger with a direction and a period * - * @param int|array $cpt Accounting account or array of accounting account + * @param string|int|array $cpt Accounting account or array of accounting account * @param int $date_start Date start * @param int $date_end Date end * @param int<0,1> $sens Sens of the account: 0: credit - debit (use this by default), 1: debit - credit diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php index 66a5130787e..f2de46762cf 100644 --- a/htdocs/compta/resultat/clientfourn.php +++ b/htdocs/compta/resultat/clientfourn.php @@ -386,7 +386,7 @@ if ($modecompta == 'BOOKKEEPING') { $cpts = $AccCat->getCptsCat(0, $tmppredefinedgroupwhere); foreach ($cpts as $j => $cpt) { - $return = $AccCat->getSumDebitCredit((int) $cpt['account_number'], $date_start, $date_end, (empty($cpt['dc']) ? 0 : $cpt['dc'])); + $return = $AccCat->getSumDebitCredit($cpt['account_number'], $date_start, $date_end, (empty($cpt['dc']) ? 0 : $cpt['dc'])); if ($return < 0) { setEventMessages(null, $AccCat->errors, 'errors'); $resultN = 0; diff --git a/htdocs/compta/resultat/result.php b/htdocs/compta/resultat/result.php index 09328db8ca3..57209912ec3 100644 --- a/htdocs/compta/resultat/result.php +++ b/htdocs/compta/resultat/result.php @@ -560,7 +560,7 @@ if ($modecompta == 'CREANCES-DETTES') { ) { //var_dump($monthtoprocess.'_'.$yeartoprocess); if (isset($cpt['account_number'])) { - $return = $AccCat->getSumDebitCredit((int) $cpt['account_number'], $date_start, $date_end, empty($cat['dc']) ? 0 : $cat['dc'], 'nofilter', $monthtoprocess, $yeartoprocess); + $return = $AccCat->getSumDebitCredit($cpt['account_number'], $date_start, $date_end, empty($cat['dc']) ? 0 : $cat['dc'], 'nofilter', $monthtoprocess, $yeartoprocess); if ($return < 0) { setEventMessages(null, $AccCat->errors, 'errors'); $resultM = 0; From 118ae2e655a3b3ddd57e7c9b97b42d9b555a3b87 Mon Sep 17 00:00:00 2001 From: Joachim Kueter Date: Sun, 19 Jul 2026 15:52:40 +0200 Subject: [PATCH 02/14] FIX #39210 Contact extrafields filters missing on advanced emailing target selection (#39211) Typo $elementype vs $elementtype: extrafields were fetched for socpeople but read under the stale key societe, so the contact extrafields section rendered empty. --- htdocs/comm/mailing/advtargetemailing.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/comm/mailing/advtargetemailing.php b/htdocs/comm/mailing/advtargetemailing.php index acc1adf3024..1684b9904fb 100644 --- a/htdocs/comm/mailing/advtargetemailing.php +++ b/htdocs/comm/mailing/advtargetemailing.php @@ -1084,11 +1084,11 @@ if ($object->fetch($id) >= 0) { // Standard Extrafield feature if (!getDolGlobalString('MAIN_EXTRAFIELDS_DISABLED')) { $contactstatic = new Contact($db); - $elementype = $contactstatic->table_element; + $elementtype = $contactstatic->table_element; // fetch optionals attributes and labels dol_include_once('/core/class/extrafields.class.php'); $extrafields = new ExtraFields($db); - $extrafields->fetch_name_optionals_label($elementype); + $extrafields->fetch_name_optionals_label($elementtype); if (!empty($extrafields->attributes[$elementtype]['type'])) { foreach ($extrafields->attributes[$elementtype]['type'] as $key => &$value) { if ($value == 'radio') { From ad73f9d8799a8d021256f5c66fcf0d1a5d207ccb Mon Sep 17 00:00:00 2001 From: w3houde Date: Sun, 19 Jul 2026 22:31:25 +0700 Subject: [PATCH 03/14] Fix #39020 avoid duplicate MO when BOM has a sub-BOM (#39163) * Fix #39020 avoid duplicate MO when BOM has a sub-BOM When generating child MOs from a BOM with a sub-BOM line, the lookup of the parent MO consume line used a substring filter (origin_id LIKE '%id%') that was not scoped to the parent MO. It could match an unrelated mrp_production row or none at all. When it matched none, the child MO was still created from the leftover parent POST data, producing a second MO identical to the parent instead of a real child. Scope the lookup to the parent MO with an exact match on origin_id and origin_type via customsql, and skip the iteration when no matching consume line is found so no duplicate parent MO can be created. Signed-off-by: Dolicraft * Fix #39020 use exact-match filter keys instead of customsql per review Add exact-match handling for fk_mo, origin_id and origin_type in MoLine::fetchAll and call it with those keys instead of a customsql clause, so the lookup stays valid on 18.0/19.0 where customsql would be the only alternative to the buggy LIKE. The universal-search filter form is handled separately on 20.0 and later. Signed-off-by: Dolicraft --------- Signed-off-by: Dolicraft Co-authored-by: Dolicraft --- htdocs/mrp/class/mo.class.php | 4 +++- htdocs/mrp/mo_card.php | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/htdocs/mrp/class/mo.class.php b/htdocs/mrp/class/mo.class.php index b1cf985e4f3..d6eacf8b1a4 100644 --- a/htdocs/mrp/class/mo.class.php +++ b/htdocs/mrp/class/mo.class.php @@ -1923,8 +1923,10 @@ class MoLine extends CommonObjectLine $sqlwhere = array(); if (count($filter) > 0) { foreach ($filter as $key => $value) { - if ($key == 't.rowid') { + if ($key == 't.rowid' || $key == 'fk_mo' || $key == 'origin_id') { $sqlwhere[] = $key." = ".((int) $value); + } elseif ($key == 'origin_type') { + $sqlwhere[] = $key." = '".$this->db->escape($value)."'"; } elseif (strpos($key, 'date') !== false) { $sqlwhere[] = $key." = '".$this->db->idate($value)."'"; } elseif ($key == 'customsql') { diff --git a/htdocs/mrp/mo_card.php b/htdocs/mrp/mo_card.php index 6d66e835174..f71afd103ed 100644 --- a/htdocs/mrp/mo_card.php +++ b/htdocs/mrp/mo_card.php @@ -154,7 +154,15 @@ if (empty($reshook)) { $objectbomchildline->fetch($id_bom_line); - $TMoLines = $moline->fetchAll('DESC', 'rowid', '1', '', array('origin_id' => $id_bom_line)); + // Find the consume line of the parent MO generated from this BOM line. + // The lookup must be scoped to the parent MO and use an exact match on origin_id/origin_type, + // otherwise the default 'origin_id LIKE %..%' filter can return an unrelated line (or none), + // which would let the child MO be created from the leftover parent POST data (duplicate MO). + $TMoLines = $moline->fetchAll('DESC', 'rowid', '1', '', array('fk_mo' => $mo_parent->id, 'origin_id' => $id_bom_line, 'origin_type' => 'bomline')); + + if (empty($TMoLines)) { + continue; + } foreach ($TMoLines as $tmpmoline) { $_POST['fk_bom'] = $objectbomchildline->fk_bom_child; From a270e0852b647065467fd220404191d239a13fb0 Mon Sep 17 00:00:00 2001 From: Jam Balaya Date: Mon, 20 Jul 2026 09:53:33 +0900 Subject: [PATCH 04/14] FIX #39190 wrong unit price when invoicing time spent with one line per declaration (#39215) * FIX #39190 wrong unit price when invoicing time spent with one line per declaration In projet/tasks/time.php, the 'onelineperperiod' mode (invoice generation option "One line for each time spent declaration") computed the unit price as $pu_ht = price2num($value['totalvaluetodivideby3600'] / 3600, 'MU'); but totalvaluetodivideby3600 is timespent_duration (seconds) * timespent_thm (hourly rate), so dividing by 3600 yields "hours * hourly rate", which is the line total and not a unit price. The quantity passed to addline() is the number of hours, so the line was billed hours * (hours * rate) instead of hours * rate: the time is over-billed by a factor equal to the number of hours. The sibling modes are already correct: 'onelineperuser' and 'onelinepertask' divide by the recorded number of seconds. Up to 16.0 'onelineperuser' had the same /3600 expression; it was fixed there and 'onelineperperiod' was left behind. Align it with that reference implementation, including the same guard against a zero duration. Also reset $pu_ht for each generated line. $pu_ht is initialized once before the loops (with the price of the selected product/service, or 0) and this mode only had an "if (empty($pu_ht))" test, so once a price was computed for the first line every following line reused it, and lines of users with a different hourly rate got the rate of the first line. The base price is saved before the loop and restored on each iteration, so the product/service price path is preserved. * Rename variable for clarity in time.php --------- Co-authored-by: Laurent Destailleur --- htdocs/projet/tasks/time.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/projet/tasks/time.php b/htdocs/projet/tasks/time.php index 4f3b1395704..ab6d96bf512 100644 --- a/htdocs/projet/tasks/time.php +++ b/htdocs/projet/tasks/time.php @@ -616,7 +616,9 @@ if ($action == 'confirm_generateinvoice') { $arrayoftasks[$object->timespent_id]['fk_product'] = $object->timespent_fk_product; } + $pu_ht_saved = $pu_ht; // Save the base unit price (price of the selected product/service if any, 0 otherwise) foreach ($arrayoftasks as $timespent_id => $value) { + $pu_ht = $pu_ht_saved; // Reset for each line, so a line does not inherit the unit price computed for the previous one $userid = $value['user']; //$pu_ht = $value['timespent'] * $fuser->thm; @@ -625,7 +627,9 @@ if ($action == 'confirm_generateinvoice') { // If no unit price known if (empty($pu_ht)) { - $pu_ht = price2num($value['totalvaluetodivideby3600'] / 3600, 'MU'); + if ($value['timespent']) { + $pu_ht = price2num(($value['totalvaluetodivideby3600'] / $value['timespent']), 'MU'); + } } // Add lines From 7ec003387ab0d68b78d9158e9f14950cce524888 Mon Sep 17 00:00:00 2001 From: ThomasNgr-OpenDSI Date: Mon, 20 Jul 2026 15:29:30 +0200 Subject: [PATCH 05/14] 22 report sec (#39235) * Sec: sql injection via api in POST of thirdparties/id/banckaccount - reported by MDnyn * Sec: sql injection via api in POST of thirdparties/id/banckaccount - reported by MDnyn --------- Co-authored-by: Laurent Destailleur --- htdocs/accountancy/admin/productaccount.php | 2 +- htdocs/adherents/class/subscription.class.php | 6 +-- htdocs/admin/external_rss.php | 2 +- htdocs/contrat/class/contratligne.class.php | 2 +- htdocs/core/class/discount.class.php | 2 +- .../class/companybankaccount.class.php | 2 +- htdocs/user/class/userbankaccount.class.php | 2 +- test/phpunit/CodingPhpTest.php | 53 +++++++++++++++---- 8 files changed, 51 insertions(+), 20 deletions(-) diff --git a/htdocs/accountancy/admin/productaccount.php b/htdocs/accountancy/admin/productaccount.php index ecef0d2a796..5ea3e654f63 100644 --- a/htdocs/accountancy/admin/productaccount.php +++ b/htdocs/accountancy/admin/productaccount.php @@ -352,7 +352,7 @@ if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.account_number = p." . $db->sanitize($accountancy_field_name) . " AND aa.fk_pcg_version = '" . $db->escape($pcgvercode) . "'"; } if (!empty($searchCategoryProductList)) { - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_product as cp ON p.rowid = cp.fk_product"; // We'll need this table joined to the select in order to filter by categ + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON p.rowid = cp.fk_product"; // We'll need this table joined to the select in order to filter by categ } $sql .= ' WHERE p.entity IN ('.getEntity('product').')'; if (strlen(trim($search_current_account))) { diff --git a/htdocs/adherents/class/subscription.class.php b/htdocs/adherents/class/subscription.class.php index c021e335604..727de08e0b6 100644 --- a/htdocs/adherents/class/subscription.class.php +++ b/htdocs/adherents/class/subscription.class.php @@ -518,9 +518,9 @@ class Subscription extends CommonObject */ public function info($id) { - $sql = 'SELECT c.rowid, c.datec, c.tms as datem, c.fk_user_creat'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'subscription as c'; - $sql .= ' WHERE c.rowid = '.((int) $id); + $sql = "SELECT c.rowid, c.datec, c.tms as datem, c.fk_user_creat"; + $sql .= " FROM ".MAIN_DB_PREFIX."subscription as c"; + $sql .= " WHERE c.rowid = ".((int) $id); $resql = $this->db->query($sql); if ($resql) { diff --git a/htdocs/admin/external_rss.php b/htdocs/admin/external_rss.php index 9a8e79bae72..e16da408523 100644 --- a/htdocs/admin/external_rss.php +++ b/htdocs/admin/external_rss.php @@ -148,7 +148,7 @@ if (GETPOST("delete")) { $obj = $db->fetch_object($resql); $sql = "DELETE FROM ".MAIN_DB_PREFIX."boxes"; - $sql .= " WHERE entity = ".$conf->entity; + $sql .= " WHERE entity = ".((int) $conf->entity); $sql .= " AND box_id = ".((int) $obj->rowid); $resql = $db->query($sql); diff --git a/htdocs/contrat/class/contratligne.class.php b/htdocs/contrat/class/contratligne.class.php index b0d01da8338..7815f701dd6 100644 --- a/htdocs/contrat/class/contratligne.class.php +++ b/htdocs/contrat/class/contratligne.class.php @@ -839,7 +839,7 @@ class ContratLigne extends CommonObjectLine if ($this->date_end > 0) { $sql .= ",date_fin_validite"; } - $sql .= ") VALUES ($this->fk_contrat, '', '".$this->db->escape($this->description)."',"; + $sql .= ") VALUES (".((int) $this->fk_contrat).", '', '".$this->db->escape($this->description)."',"; $sql .= ($this->fk_product > 0 ? $this->fk_product : "null").","; $sql .= " '".$this->db->escape((string) $this->qty)."',"; $sql .= " '".$this->db->escape($this->vat_src_code)."',"; diff --git a/htdocs/core/class/discount.class.php b/htdocs/core/class/discount.class.php index 3058ceb20ca..ef8b4025a6d 100644 --- a/htdocs/core/class/discount.class.php +++ b/htdocs/core/class/discount.class.php @@ -349,7 +349,7 @@ class DiscountAbsolute extends CommonObject $sql .= " multicurrency_amount_ht, multicurrency_amount_tva, multicurrency_amount_ttc,"; $sql .= " fk_facture_source, fk_invoice_supplier_source, multicurrency_code, multicurrency_tx"; $sql .= ")"; - $sql .= " VALUES (".$conf->entity.", '".$this->db->idate($this->datec != '' ? $this->datec : dol_now())."', ".((int) $this->socid).", ".(empty($this->discount_type) ? 0 : intval($this->discount_type)).", ".((int) $userid).", '".$this->db->escape($this->description)."',"; + $sql .= " VALUES (".((int) $conf->entity).", '".$this->db->idate($this->datec != '' ? $this->datec : dol_now())."', ".((int) $this->socid).", ".(empty($this->discount_type) ? 0 : intval($this->discount_type)).", ".((int) $userid).", '".$this->db->escape($this->description)."',"; $sql .= " ".price2num($this->amount_ht).", ".price2num($this->amount_tva).", ".price2num($this->amount_ttc).", ".price2num($this->tva_tx).", '".$this->db->escape($this->vat_src_code)."',"; $sql .= " ".price2num($this->multicurrency_amount_ht).", ".price2num($this->multicurrency_amount_tva).", ".price2num($this->multicurrency_amount_ttc).", "; $sql .= " ".($this->fk_facture_source ? ((int) $this->fk_facture_source) : "null").","; diff --git a/htdocs/societe/class/companybankaccount.class.php b/htdocs/societe/class/companybankaccount.class.php index c6832d92084..2fc761c9f22 100644 --- a/htdocs/societe/class/companybankaccount.class.php +++ b/htdocs/societe/class/companybankaccount.class.php @@ -396,7 +396,7 @@ class CompanyBankAccount extends Account $this->db->begin(); $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_rib (fk_soc, type, datec, model_pdf)"; - $sql .= " VALUES (".((int) $this->socid).", '".$this->type."', '".$this->db->idate($this->datec)."',"; + $sql .= " VALUES (".((int) $this->socid).", '".$this->db->escape($this->type)."', '".$this->db->idate($this->datec)."',"; $sql .= " '".$this->db->escape(getDolGlobalString("BANKADDON_PDF"))."'"; $sql .= ")"; $resql = $this->db->query($sql); diff --git a/htdocs/user/class/userbankaccount.class.php b/htdocs/user/class/userbankaccount.class.php index 19db5f1514e..be10af47621 100644 --- a/htdocs/user/class/userbankaccount.class.php +++ b/htdocs/user/class/userbankaccount.class.php @@ -96,7 +96,7 @@ class UserBankAccount extends Account $now = dol_now(); $sql = "INSERT INTO ".$this->db->prefix()."user_rib (fk_user, datec)"; - $sql .= " VALUES (".$this->userid.", '".$this->db->idate($now)."')"; + $sql .= " VALUES (".((int) $this->userid).", '".$this->db->idate($now)."')"; $resql = $this->db->query($sql); if ($resql) { if ($this->db->affected_rows($resql)) { diff --git a/test/phpunit/CodingPhpTest.php b/test/phpunit/CodingPhpTest.php index 6e6ff0196e9..afdc98068bf 100644 --- a/test/phpunit/CodingPhpTest.php +++ b/test/phpunit/CodingPhpTest.php @@ -117,7 +117,7 @@ class CodingPhpTest extends CommonClassTest // To process only 1 file, uncomment this /* foreach($returnlist as $key => $val) { - if ($val[0]['name'] != 'societe.class.php') { + if ($val[0]['name'] != 'companybankaccount.class.php') { unset($returnlist[$key]); } } @@ -407,21 +407,52 @@ class CodingPhpTest extends CommonClassTest } $this->assertTrue($ok, 'Found a forged SQL string that mix on same line the use of \' for PHP string and PHP variables in file '.$file['relativename'].' Use " to forge PHP string like this: $sql = "SELECT ".$myvar...'); - // Check sql string VALUES ... , ".$xxx + // Check sql string VALUES ... , ".$xxx or string VALUES ... , '".$xxx // with xxx that is not 'db-' (for $db->escape). It means we forget a ' if string, or an (int) if int, when forging sql request. + // ... = " VALUES (".((int) $this->socid).", '".$this->type."', '".$this->db->idate($this->datec)."',"; + $ok = true; $matches = array(); - preg_match_all('/(VALUES).*,\s*"\s*\.\s*\$(...)/', $filecontent, $matches, PREG_SET_ORDER); + preg_match_all('/(VALUES).*,\s*\'?"\s*\.\s*\$([a-z\-\>]+)/', $filecontent, $matches, PREG_SET_ORDER); foreach ($matches as $key => $val) { - if ($val[1] == 'VALUES' && $val[2] == 'db-') { // exclude $db->escape( - continue; + $matches2 = array(); + preg_match_all('/,\s*\'?"\s*\.\s*\$([a-z\-\>]+)/', $val[0], $matches2, PREG_SET_ORDER); + foreach ($matches2 as $key2 => $val2) { + if ($val2[1] == 'mydb->escape') { // exclude ".$mydb->escape( + continue; + } + if ($val2[1] == 'dbsession->escape') { // exclude ".$dbsession->escape( + continue; + } + if ($val2[1] == 'dbsession->idate') { // exclude ".$dbsession->escape( + continue; + } + if ($val2[1] == 'this->db->encrypt') { // exclude ".$this->db->encrypt( + continue; + } + if ($val2[1] == 'this->db->escape') { // exclude ".$this->db->escape( + continue; + } + if ($val2[1] == 'this->db->idate') { // exclude ".$this->db->idate( + continue; + } + if ($val2[1] == 'db->encrypt') { // exclude ".$db->encrypt( + continue; + } + if ($val2[1] == 'db->escape') { // exclude ".$db->escape( + continue; + } + if ($val2[1] == 'db->idate') { // exclude ".$db->idate( + continue; + } + if ($val2[1] == 'this->escape') { // exclude ".$this->db->encrypt( + continue; + } + + var_dump($matches2); + $ok = false; + break; } - if ($val[1] == 'VALUES' && $val[2] == 'thi' && preg_match('/this->db->encrypt/', $val[0])) { // exclude ".$this->db->encrypt( - continue; - } - var_dump($matches); - $ok = false; - break; } //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n"; $this->assertTrue($ok, 'Found non quoted or not casted var in sql request '.$file['relativename'].' - Bad.'); From 797312579bef01cec9a67b5dab026ecb683c1286 Mon Sep 17 00:00:00 2001 From: Jam Balaya Date: Mon, 20 Jul 2026 22:30:28 +0900 Subject: [PATCH 06/14] FIX isInt() does not detect sized integer types (tinyint, bigint) (#39236) CommonObject::isInt() decides whether a list-page column gets numeric search mode and is also used when resolving $this->id. The regex /(^int|int$)/ missed sized integer types such as tinyint(4) and bigint(20): they neither start nor end with "int". These types are not exotic: tinyint(4) is used in several core $fields definitions (societe, contact, entrepot, companypaymentmode, ...) and ModuleBuilder-generated tables use bigint(20) for rowid, so isInt() should recognise them rather than requiring callers to change the column type. The new regex /^(?:tiny|small|medium|big)?int|int$/ also handles smallint/mediumint with a size. Anchoring is preserved on purpose so that strings which merely contain "int" (e.g. sellist:Table:...) are still NOT matched, while the Dolibarr foreign-key syntax "integer:Class:path" keeps being detected. Signed-off-by: Jam Balaya --- htdocs/core/class/commonobject.class.php | 2 +- test/phpunit/CommonObjectTest.php | 34 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 1da7bc7eb97..c048c968545 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -10059,7 +10059,7 @@ abstract class CommonObject public function isInt($info) { if (is_array($info)) { - if (isset($info['type']) && (preg_match('/(^int|int$)/i', $info['type']))) { + if (isset($info['type']) && (preg_match('/^(?:tiny|small|medium|big)?int|int$/i', $info['type']))) { return true; } else { return false; diff --git a/test/phpunit/CommonObjectTest.php b/test/phpunit/CommonObjectTest.php index 49f63efddc7..2e8e4da47d7 100644 --- a/test/phpunit/CommonObjectTest.php +++ b/test/phpunit/CommonObjectTest.php @@ -117,4 +117,38 @@ class CommonObjectTest extends CommonClassTest $this->assertLessThanOrEqual($result, 0); return $result; } + + /** + * testIsInt + * + * @return void + */ + public function testIsInt() + { + global $conf,$user,$langs,$db; + $conf = $this->savconf; + $user = $this->savuser; + $langs = $this->savlangs; + $db = $this->savdb; + + $localobject = new Commande($db); + + // Integer types, with or without a size/unsigned suffix, must be detected. + $this->assertTrue($localobject->isInt(array('type' => 'int')), 'int'); + $this->assertTrue($localobject->isInt(array('type' => 'int(11)')), 'int(11)'); + $this->assertTrue($localobject->isInt(array('type' => 'integer')), 'integer'); + $this->assertTrue($localobject->isInt(array('type' => 'tinyint(4)')), 'tinyint(4)'); + $this->assertTrue($localobject->isInt(array('type' => 'smallint(6)')), 'smallint(6)'); + $this->assertTrue($localobject->isInt(array('type' => 'bigint(20)')), 'bigint(20)'); + // Dolibarr foreign-key column syntax "integer:Class:path" must keep being detected. + $this->assertTrue($localobject->isInt(array('type' => 'integer:User:user/class/user.class.php')), 'integer:User:...'); + + // Non-integer types must not be detected, including strings that merely contain "int". + $this->assertFalse($localobject->isInt(array('type' => 'varchar(255)')), 'varchar(255)'); + $this->assertFalse($localobject->isInt(array('type' => 'double(24,8)')), 'double(24,8)'); + $this->assertFalse($localobject->isInt(array('type' => 'date')), 'date'); + $this->assertFalse($localobject->isInt(array('type' => 'sellist:llx_c_typent:libelle:id')), 'sellist:...'); + + print __METHOD__." OK\n"; + } } From 136be3c1968cd43dc658c3860da82697a2bffeb9 Mon Sep 17 00:00:00 2001 From: Jam Balaya Date: Wed, 22 Jul 2026 03:31:00 +0900 Subject: [PATCH 07/14] FIX #34667 checkUserAccessToObject: skip entity check for non-multientity objects (multicompany) (#39246) When the multicompany module is enabled, checkUserAccessToObject() (used by restrictedArea(), e.g. from an ajax tooltip) ran the entity check unconditionally in its default/custom-object branch, building "AND dbt.entity IN (...)". For a custom object whose table has no entity column (ismultientitymanaged = 0), that SQL fails, nb comes back 0 and access is wrongly denied. Guard the branch so the entity test only runs when the object is actually multi-entity managed. Keep the test for legacy classes that never define ismultientitymanaged (null/unset) and for a non-object $object, and skip it only when a class explicitly sets ismultientitymanaged = 0. Supersedes the stale #34667 (by @jyhere) and applies the condition requested by @eldy in its review. Co-authored-by: Claude Opus 4.8 --- htdocs/core/lib/security.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index 15c8baec1bf..8c00a057fac 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -1187,7 +1187,7 @@ function checkUserAccessToObject($user, array $featuresarray, $object = 0, $tabl $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")"; $sql .= " AND (sc.fk_user = ".((int) $user->id)." OR sc.fk_user IS NULL)"; } - } elseif (isModEnabled('multicompany')) { + } elseif (isModEnabled('multicompany') && (!empty($object->ismultientitymanaged) || !isset($object->ismultientitymanaged))) { // If multicompany, and user is an internal user with all permissions, check that object is in correct entity $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb"; $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt"; From ed47b61151645dd7ccae0c5ecc1e4b10fb8386d4 Mon Sep 17 00:00:00 2001 From: Jam Balaya Date: Wed, 22 Jul 2026 10:35:51 +0900 Subject: [PATCH 08/14] FIX mo_production: show very-short unit label instead of untranslated 'UnitPShort' (#39253) The "Unit" column of the consume/produce tables used measuringUnitString(..., 2), which translates a