Fix: Trigger for delete must be done in opposite order than trigger for

create.
This commit is contained in:
Laurent Destailleur 2012-02-22 12:37:39 +01:00
parent 3a915de69a
commit 489c00fa9f
2 changed files with 24 additions and 42 deletions

View File

@ -23,21 +23,20 @@
/** /**
* \file htdocs/product/class/product.class.php * \file htdocs/product/class/product.class.php
* \ingroup produit * \ingroup produit
* \brief Fichier de la classe des produits predefinis * \brief File of class to manage predefined products or services
*/ */
require_once(DOL_DOCUMENT_ROOT ."/core/class/commonobject.class.php"); require_once(DOL_DOCUMENT_ROOT ."/core/class/commonobject.class.php");
/** /**
* \class Product * Class to manage products or services
* \brief Class to manage products and services
*/ */
class Product extends CommonObject class Product extends CommonObject
{ {
public $element='product'; public $element='product';
public $table_element='product'; public $table_element='product';
public $fk_element='fk_product'; public $fk_element='fk_product';
protected $childtables=array('propaldet','commandedet','facturedet','contratdet','product_fournisseur_price'); protected $childtables=array('propaldet','commandedet','facturedet','contratdet'); // To test if we can delete object
protected $isnolinkedbythird = 1; // No field fk_soc protected $isnolinkedbythird = 1; // No field fk_soc
protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
@ -526,28 +525,24 @@ class Product extends CommonObject
{ {
$this->db->begin(); $this->db->begin();
// Delete supplier prices if (! $error)
if (! $error) {
{ // Appel des triggers
$sql = 'DELETE pfp'; include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$sql.= ' FROM '.MAIN_DB_PREFIX.'product_fournisseur_price as pfp'; $interface=new Interfaces($this->db);
$sql.= ' WHERE pfp.fk_product = '.$id; $result=$interface->run_triggers('PRODUCT_DELETE',$this,$user,$langs,$conf);
dol_syslog(get_class($this).'::delete sql='.$sql, LOG_DEBUG); if ($result < 0) {
$result = $this->db->query($sql); $error++; $this->errors=$interface->errors;
if (! $result) }
{ // Fin appel triggers
$error++; }
$this->error = $this->db->lasterror();
dol_syslog(get_class($this).'::delete error '.$this->error, LOG_ERR);
}
}
// Other child tables // Delete all child tables
if (! $error) $elements = array('product_fournisseur_price','product_price','product_lang','categorie_product');
{ foreach($elements as $table)
$elements = array('product_price','product_lang','categorie_product'); {
foreach($elements as $table) if (! $error)
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX.$table; $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table;
$sql.= " WHERE fk_product = ".$id; $sql.= " WHERE fk_product = ".$id;
dol_syslog(get_class($this).'::delete sql='.$sql, LOG_DEBUG); dol_syslog(get_class($this).'::delete sql='.$sql, LOG_DEBUG);
@ -558,13 +553,10 @@ class Product extends CommonObject
$this->error = $this->db->lasterror(); $this->error = $this->db->lasterror();
dol_syslog(get_class($this).'::delete error '.$this->error, LOG_ERR); dol_syslog(get_class($this).'::delete error '.$this->error, LOG_ERR);
} }
} }
} }
// Removed extrafields
//$result=$this->deleteExtraFields($this);
//if ($result < 0) $error++;
// TODO Remove this. It can already be addressed by previous triggers
if (! $error) if (! $error)
{ {
// Actions on extra fields (by external module or standard code) // Actions on extra fields (by external module or standard code)
@ -595,16 +587,6 @@ 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
}
if ($error) if ($error)
{ {
$this->db->rollback(); $this->db->rollback();

View File

@ -39,7 +39,7 @@ class Societe extends CommonObject
public $element='societe'; public $element='societe';
public $table_element = 'societe'; public $table_element = 'societe';
public $fk_element='fk_soc'; public $fk_element='fk_soc';
protected $childtables=array("propal","commande","facture","contrat","facture_fourn","commande_fournisseur"); protected $childtables=array("propal","commande","facture","contrat","facture_fourn","commande_fournisseur"); // To test if we can delete object
protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
var $id; var $id;