Browse Source

FIX : default value for bom_id with $this->id and protection against infinite loop

Gauthier PC portable 024 2 years ago
parent
commit
c28407a1c9
2 changed files with 11 additions and 3 deletions
  1. 1 1
      htdocs/bom/bom_card.php
  2. 10 2
      htdocs/bom/class/bom.class.php

+ 1 - 1
htdocs/bom/bom_card.php

@@ -182,7 +182,7 @@ if (empty($reshook)) {
 
 		// We check if we're allowed to add this bom
 		$TParentBom=array();
-		$object->getParentBomTreeRecursive($TParentBom, $object->id);
+		$object->getParentBomTreeRecursive($TParentBom);
 		if ($bom_child_id > 0 && !empty($TParentBom) && in_array($bom_child_id, $TParentBom)) {
 			$n_child = new BOM($db);
 			$n_child->fetch($bom_child_id);

+ 10 - 2
htdocs/bom/class/bom.class.php

@@ -1153,11 +1153,19 @@ class BOM extends CommonObject
 	 *
 	 * @param 	array	$TParentBom		We put all found parent bom in $TParentBom
 	 * @param 	int		$bom_id			ID of bom from which we want to get parent bom ids
+	 * @param 	int		$level		Protection against infinite loop
 	 * @return 	void
 	 */
-	public function getParentBomTreeRecursive(&$TParentBom, $bom_id)
+	public function getParentBomTreeRecursive(&$TParentBom, $bom_id='', $level=1)
 	{
 
+		// Protection against infinite loop
+		if ($level > 1000) {
+			return 0;
+		}
+
+		if(empty($bom_id)) $bom_id=$this->id;
+
 		$sql = 'SELECT l.fk_bom, b.label
 				FROM '.MAIN_DB_PREFIX.'bom_bomline l
 				INNER JOIN '.MAIN_DB_PREFIX.$this->table_element.' b ON b.rowid = l.fk_bom
@@ -1167,7 +1175,7 @@ class BOM extends CommonObject
 		if (!empty($resql)) {
 			while ($res = $this->db->fetch_object($resql)) {
 				$TParentBom[$res->fk_bom] = $res->fk_bom;
-				$this->getParentBomTreeRecursive($TParentBom, $res->fk_bom);
+				$this->getParentBomTreeRecursive($TParentBom, $res->fk_bom, $level+1);
 			}
 		}
 	}