Refactor: BILL_* and LINEBILL_* trigger

This commit is contained in:
KreizIT 2014-07-11 14:36:13 +02:00
parent 8e64ea274d
commit fc61cc9bfa
2 changed files with 61 additions and 106 deletions

View File

@ -43,6 +43,7 @@ For developers:
- New: Add trigger DON_UPDATE, DON_DELETE - New: Add trigger DON_UPDATE, DON_DELETE
- New: Add country iso code on 3 chars into table of countries. - New: Add country iso code on 3 chars into table of countries.
- Qual: Removed hard coded rowid into data init of table llx_c_action_trigger. - Qual: Removed hard coded rowid into data init of table llx_c_action_trigger.
- LINEBILL_DELETE trigger called before SQL delete in facturedet
WARNING: Following change may create regression for some external modules, but was necessary to make WARNING: Following change may create regression for some external modules, but was necessary to make
Dolibarr better: Dolibarr better:

View File

@ -482,14 +482,10 @@ class Facture extends CommonInvoice
} }
else if ($reshook < 0) $error++; else if ($reshook < 0) $error++;
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('BILL_CREATE',$user);
$interface=new Interfaces($this->db); if ($result < 0) $error++;
$result=$interface->run_triggers('BILL_CREATE',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
if (! $error) if (! $error)
{ {
@ -655,14 +651,10 @@ class Facture extends CommonInvoice
if ($reshook < 0) $error++; if ($reshook < 0) $error++;
} }
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('BILL_CLONE',$user);
$interface=new Interfaces($this->db); if ($result < 0) $error++;
$result=$interface->run_triggers('BILL_CLONE',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
} }
// End // End
@ -1100,14 +1092,10 @@ class Facture extends CommonInvoice
{ {
if (! $notrigger) if (! $notrigger)
{ {
// Call triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('BILL_MODIFY',$user);
$interface=new Interfaces($this->db); if ($result < 0) $error++;
$result=$interface->run_triggers('BILL_MODIFY',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// End call triggers
} }
} }
@ -1262,14 +1250,10 @@ class Facture extends CommonInvoice
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('BILL_DELETE',$user);
$interface=new Interfaces($this->db); if ($result < 0) $error++;
$result=$interface->run_triggers('BILL_DELETE',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
} }
// Removed extrafields // Removed extrafields
@ -1403,7 +1387,6 @@ class Facture extends CommonInvoice
} }
else else
{ {
$this->error=$this->db->lasterror();
$this->db->rollback(); $this->db->rollback();
return -2; return -2;
} }
@ -1439,14 +1422,10 @@ class Facture extends CommonInvoice
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('BILL_PAYED',$user);
$interface=new Interfaces($this->db); if ($result < 0) $error++;
$result=$interface->run_triggers('BILL_PAYED',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
} }
else else
{ {
@ -1495,14 +1474,10 @@ class Facture extends CommonInvoice
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('BILL_UNPAYED',$user);
$interface=new Interfaces($this->db); if ($result < 0) $error++;
$result=$interface->run_triggers('BILL_UNPAYED',$this,$user,$langs,$conf); // End call triggers
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
} }
else else
{ {
@ -1562,18 +1537,14 @@ class Facture extends CommonInvoice
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('BILL_CANCEL',$user);
$interface=new Interfaces($this->db); if ($result < 0)
$result=$interface->run_triggers('BILL_CANCEL',$this,$user,$langs,$conf); {
if ($result < 0) {
$error++;
$this->errors=$interface->errors;
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
// Fin appel triggers // End call triggers
$this->db->commit(); $this->db->commit();
return 1; return 1;
@ -1791,14 +1762,11 @@ class Facture extends CommonInvoice
// Trigger calls // Trigger calls
if (! $error) if (! $error)
{ {
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('BILL_VALIDATE',$user);
$interface=new Interfaces($this->db); if ($result < 0) $error++;
$result=$interface->run_triggers('BILL_VALIDATE',$this,$user,$langs,$conf); //TODO: Restoring ref, facnumber, statut, brouillon to previous value if trigger fail
if ($result < 0) { // End call triggers
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
} }
} }
else else
@ -1872,17 +1840,15 @@ class Facture extends CommonInvoice
$old_statut=$this->statut; $old_statut=$this->statut;
$this->brouillon = 1; $this->brouillon = 1;
$this->statut = 0; $this->statut = 0;
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('BILL_UNVALIDATE',$user);
$interface=new Interfaces($this->db); if ($result < 0)
$result=$interface->run_triggers('BILL_UNVALIDATE',$this,$user,$langs,$conf); {
if ($result < 0) {
$error++; $error++;
$this->errors=$interface->errors;
$this->statut=$old_statut; $this->statut=$old_statut;
$this->brouillon=0; $this->brouillon=0;
} }
// Fin appel triggers // End call triggers
} else { } else {
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
@ -3567,18 +3533,14 @@ class FactureLigne extends CommonInvoiceLine
if (! $notrigger) if (! $notrigger)
{ {
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('LINEBILL_INSERT',$user);
$interface=new Interfaces($this->db); if ($result < 0)
$result = $interface->run_triggers('LINEBILL_INSERT',$this,$user,$langs,$conf); {
if ($result < 0)
{
$error++;
$this->errors=$interface->errors;
$this->db->rollback(); $this->db->rollback();
return -2; return -2;
} }
// Fin appel triggers // End call triggers
} }
$this->db->commit(); $this->db->commit();
@ -3683,18 +3645,14 @@ class FactureLigne extends CommonInvoiceLine
if (! $notrigger) if (! $notrigger)
{ {
// Appel des triggers // Call trigger
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $result=$this->call_trigger('LINEBILL_UPDATE',$user);
$interface=new Interfaces($this->db); if ($result < 0)
$result = $interface->run_triggers('LINEBILL_UPDATE',$this,$user,$langs,$conf); {
if ($result < 0)
{
$error++;
$this->errors=$interface->errors;
$this->db->rollback(); $this->db->rollback();
return -2; return -2;
} }
// Fin appel triggers // End call triggers
} }
$this->db->commit(); $this->db->commit();
return 1; return 1;
@ -3720,25 +3678,21 @@ class FactureLigne extends CommonInvoiceLine
$this->db->begin(); $this->db->begin();
// Call trigger
$result=$this->call_trigger('LINEBILL_DELETE',$user);
if ($result < 0)
{
$this->db->rollback();
return -1;
}
// End call triggers
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = ".$this->rowid; $sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = ".$this->rowid;
dol_syslog(get_class($this)."::delete", LOG_DEBUG); dol_syslog(get_class($this)."::delete", LOG_DEBUG);
if ($this->db->query($sql) ) if ($this->db->query($sql) )
{ {
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result = $interface->run_triggers('LINEBILL_DELETE',$this,$user,$langs,$conf);
if ($result < 0)
{
$error++;
$this->errors=$interface->errors;
$this->db->rollback();
return -1;
}
// Fin appel triggers
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
else else