Fix: [ bug #1465, #1466 ] Product triggers problem

This commit is contained in:
KreizIT 2014-07-04 15:54:20 +02:00
parent 1ded34aa97
commit 012fc4e8fe
3 changed files with 50 additions and 46 deletions

View File

@ -20,6 +20,7 @@ For users:
- Fix: [ bug #1505, #1504] Project trigger problem - Fix: [ bug #1505, #1504] Project trigger problem
- Fix: [ bug #1463, #1464 ] Proposal triggers problem - Fix: [ bug #1463, #1464 ] Proposal triggers problem
- Fix: [ bug #1498, #1499 ] Shipment/Delivery triggers problem - Fix: [ bug #1498, #1499 ] Shipment/Delivery triggers problem
- Fix: [ bug #1465, #1466 ] Product triggers problem
For translators: For translators:
- Update language files. - Update language files.

View File

@ -222,6 +222,10 @@ class InterfaceDemo
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
} }
elseif ($action == 'PRODUCT_DELETE') 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); dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
} }

View File

@ -427,12 +427,10 @@ class Product extends CommonObject
if (! $error && ! $notrigger) if (! $error && ! $notrigger)
{ {
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('PRODUCT_CREATE',$user);
$interface=new Interfaces($this->db); if ($result < 0) { $error++; }
$result=$interface->run_triggers('PRODUCT_CREATE',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
} }
if (! $error) if (! $error)
@ -665,12 +663,10 @@ class Product extends CommonObject
if (! $error && ! $notrigger) if (! $error && ! $notrigger)
{ {
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('PRODUCT_MODIFY',$user);
$interface=new Interfaces($this->db); if ($result < 0) { $error++; }
$result=$interface->run_triggers('PRODUCT_MODIFY',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
} }
if (! $error && (is_object($this->oldcopy) && $this->oldcopy->ref != $this->ref)) if (! $error && (is_object($this->oldcopy) && $this->oldcopy->ref != $this->ref))
@ -763,34 +759,33 @@ class Product extends CommonObject
if (! $error) if (! $error)
{ {
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('PRODUCT_DELETE',$user);
$interface=new Interfaces($this->db); if ($result < 0) { $error++; }
$result=$interface->run_triggers('PRODUCT_DELETE',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
} }
// Delete all child tables // Delete all child tables
$elements = array('product_fournisseur_price','product_price','product_lang','categorie_product','product_stock'); if (! $error)
foreach($elements as $table)
{ {
if (! $error) $elements = array('product_fournisseur_price','product_price','product_lang','categorie_product','product_stock');
{ foreach($elements as $table)
$sql = "DELETE FROM ".MAIN_DB_PREFIX.$table; {
$sql.= " WHERE fk_product = ".$id; if (! $error)
dol_syslog(get_class($this).'::delete', LOG_DEBUG); {
$result = $this->db->query($sql); $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table;
if (! $result) $sql.= " WHERE fk_product = ".$id;
{ dol_syslog(get_class($this).'::delete', LOG_DEBUG);
$error++; $result = $this->db->query($sql);
$this->errors[] = $this->db->lasterror(); if (! $result)
} {
} $error++;
$this->errors[] = $this->db->lasterror();
}
}
}
} }
// Delete product // Delete product
if (! $error) if (! $error)
{ {
@ -1227,6 +1222,8 @@ class Product extends CommonObject
$localtax2=get_localtax($newvat,2); $localtax2=get_localtax($newvat,2);
if (empty($localtax1)) $localtax1=0; // If = '' then = 0 if (empty($localtax1)) $localtax1=0; // If = '' then = 0
if (empty($localtax2)) $localtax2=0; // If = '' then = 0 if (empty($localtax2)) $localtax2=0; // If = '' then = 0
$this->db->begin();
// Ne pas mettre de quote sur les numeriques decimaux. // Ne pas mettre de quote sur les numeriques decimaux.
// Ceci provoque des stockages avec arrondis en base au lieu des valeurs exactes. // 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 $this->level = $level; // Store level of price edited for trigger
// Appel des triggers // Call trigger
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); $result=$this->call_trigger('PRODUCT_PRICE_MODIFY',$user);
$interface=new Interfaces($this->db); if ($result < 0)
$result=$interface->run_triggers('PRODUCT_PRICE_MODIFY',$this,$user,$langs,$conf); {
if ($result < 0) $this->db->rollback();
{ return -1;
$error++; $this->errors=$interface->errors; }
} // End call triggers
// Fin appel triggers
$this->db->commit();
} }
else else
{ {
dol_print_error($this->db); $this->db->rollback();
dol_print_error($this->db);
} }
} }