FIX : default value for bom_id with $this->id and protection against infinite loop
This commit is contained in:
parent
f1e98f2d35
commit
c28407a1c9
@ -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);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user