From 012fc4e8fee6b800e09ec7fc6e02ae7792177fd0 Mon Sep 17 00:00:00 2001 From: KreizIT Date: Fri, 4 Jul 2014 15:54:20 +0200 Subject: [PATCH] Fix: [ bug #1465, #1466 ] Product triggers problem --- ChangeLog | 1 + .../interface_90_all_Demo.class.php-NORUN | 4 + htdocs/product/class/product.class.php | 91 +++++++++---------- 3 files changed, 50 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index cb93b839133..0c80f04d4b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,6 +20,7 @@ For users: - Fix: [ bug #1505, #1504] Project trigger problem - Fix: [ bug #1463, #1464 ] Proposal triggers problem - Fix: [ bug #1498, #1499 ] Shipment/Delivery triggers problem +- Fix: [ bug #1465, #1466 ] Product triggers problem For translators: - Update language files. diff --git a/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN b/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN index 62b758739c7..f19d717043a 100644 --- a/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN +++ b/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN @@ -222,6 +222,10 @@ class InterfaceDemo dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); } elseif ($action == 'PRODUCT_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'PRODUCT_PRICE_MODIFY') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); } diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 73859378d65..adf45fed387 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -427,12 +427,10 @@ class Product extends CommonObject if (! $error && ! $notrigger) { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('PRODUCT_CREATE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers + // Call trigger + $result=$this->call_trigger('PRODUCT_CREATE',$user); + if ($result < 0) { $error++; } + // End call triggers } if (! $error) @@ -665,12 +663,10 @@ class Product extends CommonObject if (! $error && ! $notrigger) { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('PRODUCT_MODIFY',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers + // Call trigger + $result=$this->call_trigger('PRODUCT_MODIFY',$user); + if ($result < 0) { $error++; } + // End call triggers } if (! $error && (is_object($this->oldcopy) && $this->oldcopy->ref != $this->ref)) @@ -763,34 +759,33 @@ class Product extends CommonObject if (! $error) { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('PRODUCT_DELETE',$this,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers + // Call trigger + $result=$this->call_trigger('PRODUCT_DELETE',$user); + if ($result < 0) { $error++; } + // End call triggers } - // Delete all child tables - $elements = array('product_fournisseur_price','product_price','product_lang','categorie_product','product_stock'); - foreach($elements as $table) + // Delete all child tables + if (! $error) { - if (! $error) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table; - $sql.= " WHERE fk_product = ".$id; - dol_syslog(get_class($this).'::delete', LOG_DEBUG); - $result = $this->db->query($sql); - if (! $result) - { - $error++; - $this->errors[] = $this->db->lasterror(); - } - } + $elements = array('product_fournisseur_price','product_price','product_lang','categorie_product','product_stock'); + foreach($elements as $table) + { + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table; + $sql.= " WHERE fk_product = ".$id; + dol_syslog(get_class($this).'::delete', LOG_DEBUG); + $result = $this->db->query($sql); + if (! $result) + { + $error++; + $this->errors[] = $this->db->lasterror(); + } + } + } } - + // Delete product if (! $error) { @@ -1227,6 +1222,8 @@ class Product extends CommonObject $localtax2=get_localtax($newvat,2); if (empty($localtax1)) $localtax1=0; // If = '' then = 0 if (empty($localtax2)) $localtax2=0; // If = '' then = 0 + + $this->db->begin(); // Ne pas mettre de quote sur les numeriques decimaux. // Ceci provoque des stockages avec arrondis en base au lieu des valeurs exactes. @@ -1264,19 +1261,21 @@ class Product extends CommonObject $this->level = $level; // Store level of price edited for trigger - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('PRODUCT_PRICE_MODIFY',$this,$user,$langs,$conf); - if ($result < 0) - { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers + // Call trigger + $result=$this->call_trigger('PRODUCT_PRICE_MODIFY',$user); + if ($result < 0) + { + $this->db->rollback(); + return -1; + } + // End call triggers + + $this->db->commit(); } else { - dol_print_error($this->db); + $this->db->rollback(); + dol_print_error($this->db); } }