From e070a3eda44d2375d9f21772875ed4010a4769ec Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 19 Dec 2024 12:22:10 +0100 Subject: [PATCH] FIX broken feature, check if module is enabled --- htdocs/core/class/commonobject.class.php | 9 +++++++++ htdocs/product/class/product.class.php | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index b04f5430adc75..5c8fb1cfebf2d 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4847,6 +4847,15 @@ public function isObjectUsed($id = 0, $entity = 0) $haschild = 0; foreach ($arraytoscan as $table => $element) { //print $id.'-'.$table.'-'.$elementname.'
'; + + // Check if module is enabled (to avoid error if tables of module not created) + if (isset($element['enabled']) && !empty($element['enabled'])) { + $enabled = (int) dol_eval($element['enabled'], 1); + if (empty($enabled)) { + continue; + } + } + // Check if element can be deleted $sql = "SELECT COUNT(*) as nb"; $sql .= " FROM ".$this->db->prefix().$table." as c"; diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 24ed27c5bf7ea..dce65ae869691 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -87,9 +87,9 @@ class Product extends CommonObject 'contratdet' => array('name' => 'Contract', 'parent' => 'contrat', 'parentkey' => 'fk_contrat'), 'facture_fourn_det' => array('name' => 'SupplierInvoice', 'parent' => 'facture_fourn', 'parentkey' => 'fk_facture_fourn'), 'commande_fournisseurdet' => array('name' => 'SupplierOrder', 'parent' => 'commande_fournisseur', 'parentkey' => 'fk_commande'), - 'mrp_production' => array('name' => 'Mo', 'parent' => 'mrp_mo', 'parentkey' => 'fk_mo' ), - 'bom_bom' => array('name' => 'BOM'), - 'bom_bomline' => array('name' => 'BOMLine', 'parent' => 'bom_bom', 'parentkey' => 'fk_bom'), + 'mrp_production' => array('name' => 'Mo', 'parent' => 'mrp_mo', 'parentkey' => 'fk_mo', 'enabled' => 'isModEnabled("mrp")'), + 'bom_bom' => array('name' => 'BOM', 'enabled' => 'isModEnabled("bom")'), + 'bom_bomline' => array('name' => 'BOMLine', 'parent' => 'bom_bom', 'parentkey' => 'fk_bom', 'enabled' => 'isModEnabled("bom")'), ); /**