FIX error managent and db transaction balance

This commit is contained in:
Laurent Destailleur 2021-01-14 19:09:57 +01:00
parent ee7aacae54
commit 0d704b0714
4 changed files with 25 additions and 7 deletions

View File

@ -2896,19 +2896,21 @@ class Commande extends CommonOrder
* Classify the order as invoiced
*
* @param User $user Object user making the change
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
* @return int <0 if KO, >0 if OK
* @param int $notrigger 1=Does not execute triggers, 0=execute triggers
* @return int <0 if KO, 0 if already billed, >0 if OK
*/
public function classifyBilled(User $user, $notrigger = 0)
{
$error = 0;
$this->db->begin();
if ($this->billed)
{
return 0;
}
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET facture = 1';
$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > '.self::STATUS_DRAFT;

View File

@ -401,6 +401,7 @@ class Paiement extends CommonObject
if ($result < 0)
{
$this->error = $invoice->error;
$this->errors = $invoice->errors;
$error++;
}
}

View File

@ -179,20 +179,29 @@ class Interfaces
$objMod = new $modName($this->db);
if ($objMod)
{
$dblevelbefore = $this->db->transaction_opened;
$result = 0;
if (method_exists($objMod, 'runTrigger')) // New method to implement
{
if (method_exists($objMod, 'runTrigger')) { // New method to implement
//dol_syslog(get_class($this)."::run_triggers action=".$action." Launch runTrigger for file '".$files[$key]."'", LOG_DEBUG);
$result = $objMod->runTrigger($action, $object, $user, $langs, $conf);
} elseif (method_exists($objMod, 'run_trigger')) // Deprecated method
{
} elseif (method_exists($objMod, 'run_trigger')) { // Deprecated method
dol_syslog(get_class($this)."::run_triggers action=".$action." Launch old method run_trigger (rename your trigger into runTrigger) for file '".$files[$key]."'", LOG_WARNING);
$result = $objMod->run_trigger($action, $object, $user, $langs, $conf);
} else {
dol_syslog(get_class($this)."::run_triggers action=".$action." A trigger was declared for class ".get_class($objMod)." but method runTrigger was not found", LOG_ERR);
}
$dblevelafter = $this->db->transaction_opened;
if ($dblevelbefore != $dblevelafter) {
$errormessage = "Error, the balance begin/close of db transactions has been broken into trigger ".$modName." with action=".$action." before=".$dblevelbefore." after=".$dblevelafter;
$this->errors[] = $errormessage;
dol_syslog($errormessage, LOG_ERR);
$result = -1;
}
if ($result > 0)
{
// Action OK

View File

@ -891,11 +891,17 @@ class CommandeFournisseur extends CommonOrder
* Class invoiced the supplier order
*
* @param User $user Object user making the change
* @return int <0 if KO, >0 if KO
* @return int <0 if KO, 0 if already billed, >0 if OK
*/
public function classifyBilled(User $user)
{
$error = 0;
if ($this->billed)
{
return 0;
}
$this->db->begin();
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande_fournisseur SET billed = 1';