From 911e862a8e88a703ea54ca2b7588f7d426b87c2e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur <eldy@destailleur.fr> Date: Wed, 4 May 2016 13:49:05 +0200 Subject: [PATCH] Fix missing translation and add a TODO to avoid infinite loop. --- htdocs/langs/en_US/products.lang | 1 + htdocs/product/class/product.class.php | 14 ++++++++++---- htdocs/product/composition/card.php | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 9298bdc9669..291f04f1c7e 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -130,6 +130,7 @@ AssociatedProductsAbility=Activate the package feature AssociatedProducts=Package product AssociatedProductsNumber=Number of products composing this package product ParentProductsNumber=Number of parent packaging product +ParentProducts=Parent products IfZeroItIsNotAVirtualProduct=If 0, this product is not a package product IfZeroItIsNotUsedByVirtualProduct=If 0, this product is not used by any package product EditAssociate=Associate diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 2b109af5e68..3cc72ac9b97 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -2982,9 +2982,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) * @return array Prod */ - function getChildsArbo($id, $firstlevelonly=0) + function getChildsArbo($id, $firstlevelonly=0, $level=1) { $sql = "SELECT p.rowid, p.label as label, pa.qty as qty, pa.fk_product_fils as id, p.fk_product_type, pa.incdec"; $sql.= " FROM ".MAIN_DB_PREFIX."product as p"; @@ -2993,13 +2994,18 @@ class Product extends CommonObject $sql.= " AND pa.fk_product_pere = ".$id; $sql.= " AND pa.fk_product_fils != ".$id; // This should not happens, it is to avoid infinite loop if it happens - dol_syslog(get_class($this).'::getChildsArbo', LOG_DEBUG); + dol_syslog(get_class($this).'::getChildsArbo id='.$id.' level='.$level, LOG_DEBUG); + + // Protection against infinite loop + if ($level > 30) return array(); + $res = $this->db->query($sql); if ($res) { $prods = array(); while ($rec = $this->db->fetch_array($res)) { + // TODO Add check to not add ne record if already added $prods[$rec['rowid']]= array( 0=>$rec['id'], 1=>$rec['qty'], @@ -3011,7 +3017,7 @@ class Product extends CommonObject //$prods[$this->db->escape($rec['label'])]= array(0=>$rec['id'],1=>$rec['qty']); if (empty($firstlevelonly)) { - $listofchilds=$this->getChildsArbo($rec['id']); + $listofchilds=$this->getChildsArbo($rec['id'], 0, $level + 1); foreach($listofchilds as $keyChild => $valueChild) { $prods[$rec['rowid']]['childs'][$keyChild] = $valueChild; @@ -3041,7 +3047,7 @@ class Product extends CommonObject foreach($parent as $key => $value) // key=label, value[0]=id { - foreach($this->getChildsArbo($value[0]) as $keyChild => $valueChild) + foreach($this->getChildsArbo($value[0]) as $keyChild => $valueChild) // Warning. getChildsArbo can gell getChildsArbo recursively. { $parent[$key][$keyChild] = $valueChild; } diff --git a/htdocs/product/composition/card.php b/htdocs/product/composition/card.php index f4b3f575eba..ee99226f2e4 100644 --- a/htdocs/product/composition/card.php +++ b/htdocs/product/composition/card.php @@ -265,7 +265,7 @@ if ($id > 0 || ! empty($ref)) print load_fiche_titre($langs->trans("ProductParentList"),'','').'<br>'; print '<table class="centpercent noborder">'; print '<tr class="liste_titre">'; - print '<td>'.$langs->trans('ParentProduct').'</td>'; + print '<td>'.$langs->trans('ParentProducts').'</td>'; print '<td>'.$langs->trans('Label').'</td>'; print '<td>'.$langs->trans('Qty').'</td>'; print '</td>'; -- GitLab