From 53bf6db23fe43d7b016171bf08ae43b052856f34 Mon Sep 17 00:00:00 2001 From: NASDAMI Quatadah Date: Thu, 9 Jun 2022 13:46:04 +0200 Subject: [PATCH 1/5] commenting a line => resolves the bug --- htdocs/product/class/product.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index b6e512d25c2..fd0d165dc86 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -4681,7 +4681,7 @@ class Product extends CommonObject while ($rec = $this->db->fetch_array($res)) { if (!empty($alreadyfound[$rec['rowid']])) { dol_syslog(get_class($this).'::getChildsArbo the product id='.$rec['rowid'].' was already found at a higher level in tree. We discard to avoid infinite loop', LOG_WARNING); - continue; + //continue; } $alreadyfound[$rec['rowid']] = 1; $prods[$rec['rowid']] = array( From 66ed4aa5245995a70dfdc1ca4efc0560a5a17fd4 Mon Sep 17 00:00:00 2001 From: Quatadah Nasdami Date: Mon, 11 Jul 2022 14:04:31 +0200 Subject: [PATCH 2/5] refixing the bug --- htdocs/product/class/product.class.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index fd0d165dc86..7557f7eb77b 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -4681,7 +4681,17 @@ class Product extends CommonObject while ($rec = $this->db->fetch_array($res)) { if (!empty($alreadyfound[$rec['rowid']])) { dol_syslog(get_class($this).'::getChildsArbo the product id='.$rec['rowid'].' was already found at a higher level in tree. We discard to avoid infinite loop', LOG_WARNING); - //continue; + $hasParentInSamePath = false; + while (($fathers = $rec['rowid']->getFather()) != -1) { + foreach ($fathers as $father) { + if ($father['rowid'] == $id) { + $hasParentInSamePath = true; + break; + } + } + } + if ($hasParentInSamePath) + continue; // We discard this child if it is already found at a higher level in tree in the same branch. } $alreadyfound[$rec['rowid']] = 1; $prods[$rec['rowid']] = array( From 586d496d5a72cc025fcfa2459b9529f272a16d98 Mon Sep 17 00:00:00 2001 From: Quatadah Nasdami Date: Wed, 27 Jul 2022 11:03:29 +0200 Subject: [PATCH 3/5] done as it should --- htdocs/product/class/product.class.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 7557f7eb77b..c0590620f29 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -4647,9 +4647,10 @@ class Product extends CommonObject * @param int $id Id of product to search childs of * @param int $firstlevelonly Return only direct child * @param int $level Level of recursing call (start to 1) + * @param array $parents Array of all parents of $id * @return array Return array(prodid=>array(0=prodid, 1=>qty, 2=>product type, 3=>label, 4=>incdec, 5=>product ref) */ - public function getChildsArbo($id, $firstlevelonly = 0, $level = 1) + public function getChildsArbo($id, $firstlevelonly = 0, $level = 1, $parents = array()) { global $alreadyfound; @@ -4665,7 +4666,7 @@ class Product extends CommonObject $sql .= " AND pa.fk_product_pere = ".((int) $id); $sql .= " AND pa.fk_product_fils <> ".((int) $id); // This should not happens, it is to avoid infinite loop if it happens - dol_syslog(get_class($this).'::getChildsArbo id='.$id.' level='.$level, LOG_DEBUG); + dol_syslog(get_class($this).'::getChildsArbo id='.$id.' level='.$level. ' parents='.$parents, LOG_DEBUG); if ($level == 1) { $alreadyfound = array($id=>1); // We init array of found object to start of tree, so if we found it later (should not happened), we stop immediatly @@ -4682,12 +4683,10 @@ class Product extends CommonObject if (!empty($alreadyfound[$rec['rowid']])) { dol_syslog(get_class($this).'::getChildsArbo the product id='.$rec['rowid'].' was already found at a higher level in tree. We discard to avoid infinite loop', LOG_WARNING); $hasParentInSamePath = false; - while (($fathers = $rec['rowid']->getFather()) != -1) { - foreach ($fathers as $father) { - if ($father['rowid'] == $id) { - $hasParentInSamePath = true; - break; - } + for ($i = 0; $i < count($parents); $i++) { + if ($parents[$i] == $rec['id']) { + $hasParentInSamePath = true; + break; } } if ($hasParentInSamePath) @@ -4705,7 +4704,7 @@ class Product extends CommonObject //$prods[$this->db->escape($rec['label'])]= array(0=>$rec['id'],1=>$rec['qty'],2=>$rec['fk_product_type']); //$prods[$this->db->escape($rec['label'])]= array(0=>$rec['id'],1=>$rec['qty']); if (empty($firstlevelonly)) { - $listofchilds = $this->getChildsArbo($rec['rowid'], 0, $level + 1); + $listofchilds = $this->getChildsArbo($rec['rowid'], 0, $level + 1, array_push($parents, $rec['rowid'])); foreach ($listofchilds as $keyChild => $valueChild) { $prods[$rec['rowid']]['childs'][$keyChild] = $valueChild; } From 2d60fe26f974c53a9b38d8fb2a64274720d45553 Mon Sep 17 00:00:00 2001 From: Quatadah Nasdami Date: Wed, 27 Jul 2022 11:07:28 +0200 Subject: [PATCH 4/5] done as it should --- htdocs/product/class/product.class.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index c0590620f29..5374a216175 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -4682,15 +4682,9 @@ class Product extends CommonObject while ($rec = $this->db->fetch_array($res)) { if (!empty($alreadyfound[$rec['rowid']])) { dol_syslog(get_class($this).'::getChildsArbo the product id='.$rec['rowid'].' was already found at a higher level in tree. We discard to avoid infinite loop', LOG_WARNING); - $hasParentInSamePath = false; - for ($i = 0; $i < count($parents); $i++) { - if ($parents[$i] == $rec['id']) { - $hasParentInSamePath = true; - break; - } + if (in_array($rec['id'], $parents)) { + continue; // We discard this child if it is already found at a higher level in tree in the same branch. } - if ($hasParentInSamePath) - continue; // We discard this child if it is already found at a higher level in tree in the same branch. } $alreadyfound[$rec['rowid']] = 1; $prods[$rec['rowid']] = array( From 6a27df53f9a47fb0ad2ff2dd0a19378b29cff751 Mon Sep 17 00:00:00 2001 From: Sylvain Legrand Date: Sun, 14 Aug 2022 16:28:44 +0200 Subject: [PATCH 5/5] Improve settings for phone number (Madagascar) --- htdocs/core/lib/functions.lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 2f9cb532708..2fd11654fb3 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3031,8 +3031,8 @@ function dol_print_phone($phone, $countrycode = '', $cid = 0, $socid = 0, $addli $newphone = substr($newphone, 0, 5).$separ.substr($newphone, 5, 3).$separ.substr($newphone, 8, 4); } } elseif (strtoupper($countrycode) == "MG") {//Madagascar - if (dol_strlen($phone) == 13) {//ex: +261_AB_CD_EF_GHI - $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 2).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 2).$separ.substr($newphone, 10, 3); + if (dol_strlen($phone) == 13) {//ex: +261_AB_CD_EFG_HI + $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 2).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 3).$separ.substr($newphone, 11, 2); } } elseif (strtoupper($countrycode) == "GB") {//Royaume uni if (dol_strlen($phone) == 13) {//ex: +44_ABCD_EFG_HIJ