From 2dbbc76645df070d0f6cd0a35f8873a96319b483 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 15 Sep 2014 11:48:50 +0200 Subject: [PATCH] Fix: Trigger error not reported --- htdocs/comm/propal.php | 40 ++++++++++++-------- htdocs/comm/propal/class/propal.class.php | 46 +++++++++++------------ htdocs/commande/fiche.php | 2 +- htdocs/compta/facture.php | 15 ++++---- htdocs/core/class/commonobject.class.php | 2 + 5 files changed, 59 insertions(+), 46 deletions(-) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 2cfa97549b1..bd95e5a67e4 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -351,7 +351,6 @@ else if ($action == 'add' && $user->rights->propal->creer) { } $id = $object->create($user); - if ($id > 0) { dol_include_once('/' . $element . '/class/' . $subelement . '.class.php'); @@ -435,11 +434,11 @@ else if ($action == 'add' && $user->rights->propal->creer) { if ($reshook < 0) $error ++; } else { - $mesgs [] = $srcobject->error; + setEventMessages($srcobject->error, $srcobject->errors, 'errors'); $error ++; } } else { - $mesgs [] = $object->error; + setEventMessages($object->error, $object->errors, 'errors'); $error ++; } } // Standard creation @@ -448,23 +447,29 @@ else if ($action == 'add' && $user->rights->propal->creer) { $id = $object->create($user); } - if ($id > 0) { + if ($id > 0) + { // Insertion contact par defaut si defini - if (GETPOST('contactidp') > 0) { + if (GETPOST('contactidp') > 0) + { $result = $object->add_contact(GETPOST('contactidp'), 'CUSTOMER', 'external'); - if ($result < 0) { - $error ++; + if ($result < 0) + { + $error++; setEventMessage($langs->trans("ErrorFailedToAddContact"), 'errors'); } } - if (! $error) { + if (! $error) + { $db->commit(); - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { // Define output language $outputlangs = $langs; - if (! empty($conf->global->MAIN_MULTILANGS)) { + if (! empty($conf->global->MAIN_MULTILANGS)) + { $outputlangs = new Translate("", $conf); $newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->thirdparty->default_lang); $outputlangs->setDefaultLang($newlang); @@ -475,13 +480,18 @@ else if ($action == 'add' && $user->rights->propal->creer) { header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $id); exit(); - } else { - $db->rollback(); } - } else { - dol_print_error($db, $object->error); + else + { + $db->rollback(); + $action='create'; + } + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); $db->rollback(); - exit(); + $action='create'; } } } diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 1b7f50b8339..45fe7ff47fb 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -864,20 +864,20 @@ class Propal extends CommonObject { // Call trigger $result=$this->call_trigger('PROPAL_CREATE',$user); - if ($result < 0) { $error++; } + if ($result < 0) { $error++; } // End call triggers } } else - { - $this->error=$this->db->error(); + { + $this->error=$this->db->lasterror(); $error++; } } } else - { - $this->error=$this->db->error(); + { + $this->error=$this->db->lasterror(); $error++; } @@ -895,7 +895,7 @@ class Propal extends CommonObject } else { - $this->error=$this->db->error(); + $this->error=$this->db->lasterror(); $this->db->rollback(); return -1; } @@ -1011,7 +1011,7 @@ class Propal extends CommonObject // Call trigger $result=$this->call_trigger('PROPAL_CLONE',$user); - if ($result < 0) { $error++; } + if ($result < 0) { $error++; } // End call triggers } @@ -1331,7 +1331,7 @@ class Propal extends CommonObject { // Call trigger $result=$this->call_trigger('PROPAL_VALIDATE',$user); - if ($result < 0) { $error++; } + if ($result < 0) { $error++; } // End call triggers } @@ -1669,7 +1669,7 @@ class Propal extends CommonObject { // Call trigger $result=$this->call_trigger('PROPAL_REOPEN',$user); - if ($result < 0) { $error++; } + if ($result < 0) { $error++; } // End call triggers } } @@ -1677,8 +1677,8 @@ class Propal extends CommonObject // Commit or rollback if ($error) { - if (!empty($this->errors)) - { + if (!empty($this->errors)) + { foreach($this->errors as $errmsg) { dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); @@ -1751,7 +1751,7 @@ class Propal extends CommonObject // Call trigger $result=$this->call_trigger('PROPAL_CLOSE_SIGNED',$user); - if ($result < 0) { $error++; } + if ($result < 0) { $error++; } // End call triggers } else @@ -1773,7 +1773,7 @@ class Propal extends CommonObject // Call trigger $result=$this->call_trigger('PROPAL_CLOSE_REFUSED',$user); - if ($result < 0) { $error++; } + if ($result < 0) { $error++; } // End call triggers } if ( ! $error ) @@ -2040,7 +2040,7 @@ class Propal extends CommonObject { // Call trigger $result=$this->call_trigger('PROPAL_DELETE',$user); - if ($result < 0) { $error++; } + if ($result < 0) { $error++; } // End call triggers } @@ -2520,7 +2520,7 @@ class Propal extends CommonObject { $file = $conf->global->PROPALE_ADDON.".php"; $classname = $conf->global->PROPALE_ADDON; - + // Include file with class foreach ($conf->file->dol_document_root as $dirroot) { @@ -2926,10 +2926,10 @@ class PropaleLigne extends CommonObject // Call trigger $result=$this->call_trigger('LINEPROPAL_INSERT',$user); if ($result < 0) - { + { $this->db->rollback(); - return -1; - } + return -1; + } // End call triggers } @@ -2976,10 +2976,10 @@ class PropaleLigne extends CommonObject // Call trigger $result=$this->call_trigger('LINEPROPAL_DELETE',$user); if ($result < 0) - { + { $this->db->rollback(); return -1; - } + } // End call triggers $this->db->commit(); @@ -3085,11 +3085,11 @@ class PropaleLigne extends CommonObject { // Call trigger $result=$this->call_trigger('LINEPROPAL_UPDATE',$user); - if ($result < 0) - { + if ($result < 0) + { $this->db->rollback(); return -1; - } + } // End call triggers } diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 2fda0277bec..d73a4c068e1 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -1559,7 +1559,7 @@ if ($action == 'create' && $user->rights->commande->creer) { } // Other attributes - $parameters = array('objectsrc' => $objectsrc,'colspan' => ' colspan="3"'); + $parameters = array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"', 'socid'=>$socid); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by // hook if (empty($reshook) && ! empty($extrafields->attribute_label)) { diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 2e9db8bc077..7bd05f9f806 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -605,7 +605,7 @@ else if ($action == 'add' && $user->rights->facture->creer) $ret = $extrafields->setOptionalsFromPost($extralabels, $object); if ($ret < 0) $error ++; - // Replacement invoice + // Replacement invoice if ($_POST['type'] == Facture::TYPE_REPLACEMENT) { $dateinvoice = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); @@ -716,10 +716,11 @@ else if ($action == 'add' && $user->rights->facture->creer) } - if(GETPOST('invoiceAvoirWithPaymentRestAmount', 'int')==1 && $id>0) { - + if(GETPOST('invoiceAvoirWithPaymentRestAmount', 'int')==1 && $id>0) + { $facture_source = new Facture($db); // fetch origin object if not previously defined - if($facture_source->fetch($object->fk_facture_source)>0) { + if ($facture_source->fetch($object->fk_facture_source)>0) + { $totalpaye = $facture_source->getSommePaiement(); $totalcreditnotes = $facture_source->getSumCreditNotesUsed(); $totaldeposits = $facture_source->getSumDepositsUsed(); @@ -1061,9 +1062,9 @@ else if ($action == 'add' && $user->rights->facture->creer) { $db->rollback(); $action = 'create'; - $_GET ["origin"] = $_POST["origin"]; - $_GET ["originid"] = $_POST["originid"]; - setEventMessage($object->error, 'errors'); + $_GET["origin"] = $_POST["origin"]; + $_GET["originid"] = $_POST["originid"]; + setEventMessages($object->error, $object->errors, 'errors'); } } diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 9d15e3d57c8..c26abe52b31 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3460,6 +3460,7 @@ abstract class CommonObject include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $interface=new Interfaces($this->db); $result=$interface->run_triggers($trigger_name,$this,$user,$langs,$conf); + if ($result < 0) { if (!empty($this->errors)) @@ -3471,6 +3472,7 @@ abstract class CommonObject $this->errors=$interface->errors; } } + return $result; }