From d204cfe6c64393515c1332ccc6f6b3a3d3948eb6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 2 Apr 2020 15:54:33 +0200 Subject: [PATCH] FIX Protection when database has a corrupted product id --- htdocs/product/stock/class/mouvementstock.class.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index 7b92af43ef0..e0266172463 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -109,7 +109,7 @@ class MouvementStock extends CommonObject * @param string $batch batch number * @param boolean $skip_batch If set to true, stock movement is done without impacting batch record * @param int $id_product_batch Id product_batch (when skip_batch is false and we already know which record of product_batch to use) - * @return int <0 if KO, 0 if fk_product is null, >0 if OK + * @return int <0 if KO, 0 if fk_product is null or product id does not exists, >0 if OK */ public function _create($user, $fk_product, $entrepot_id, $qty, $type, $price = 0, $label = '', $inventorycode = '', $datem = '', $eatby = '', $sellby = '', $batch = '', $skip_batch = false, $id_product_batch = 0) { @@ -155,13 +155,15 @@ class MouvementStock extends CommonObject $product = new Product($this->db); $result=$product->fetch($fk_product); - if ($result < 0) - { + if ($result < 0) { $this->error = $product->error; $this->errors = $product->errors; dol_print_error('', "Failed to fetch product"); return -1; } + if ($product->id <= 0) { // Can happen if database is corrupted + return 0; + } $this->db->begin();