Fix: Trigger error not reported

This commit is contained in:
Laurent Destailleur 2014-09-15 11:48:50 +02:00
parent b94d913440
commit 2dbbc76645
5 changed files with 59 additions and 46 deletions

View File

@ -351,7 +351,6 @@ else if ($action == 'add' && $user->rights->propal->creer) {
} }
$id = $object->create($user); $id = $object->create($user);
if ($id > 0) if ($id > 0)
{ {
dol_include_once('/' . $element . '/class/' . $subelement . '.class.php'); dol_include_once('/' . $element . '/class/' . $subelement . '.class.php');
@ -435,11 +434,11 @@ else if ($action == 'add' && $user->rights->propal->creer) {
if ($reshook < 0) if ($reshook < 0)
$error ++; $error ++;
} else { } else {
$mesgs [] = $srcobject->error; setEventMessages($srcobject->error, $srcobject->errors, 'errors');
$error ++; $error ++;
} }
} else { } else {
$mesgs [] = $object->error; setEventMessages($object->error, $object->errors, 'errors');
$error ++; $error ++;
} }
} // Standard creation } // Standard creation
@ -448,23 +447,29 @@ else if ($action == 'add' && $user->rights->propal->creer) {
$id = $object->create($user); $id = $object->create($user);
} }
if ($id > 0) { if ($id > 0)
{
// Insertion contact par defaut si defini // Insertion contact par defaut si defini
if (GETPOST('contactidp') > 0) { if (GETPOST('contactidp') > 0)
{
$result = $object->add_contact(GETPOST('contactidp'), 'CUSTOMER', 'external'); $result = $object->add_contact(GETPOST('contactidp'), 'CUSTOMER', 'external');
if ($result < 0) { if ($result < 0)
{
$error++; $error++;
setEventMessage($langs->trans("ErrorFailedToAddContact"), 'errors'); setEventMessage($langs->trans("ErrorFailedToAddContact"), 'errors');
} }
} }
if (! $error) { if (! $error)
{
$db->commit(); $db->commit();
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
{
// Define output language // Define output language
$outputlangs = $langs; $outputlangs = $langs;
if (! empty($conf->global->MAIN_MULTILANGS)) { if (! empty($conf->global->MAIN_MULTILANGS))
{
$outputlangs = new Translate("", $conf); $outputlangs = new Translate("", $conf);
$newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->thirdparty->default_lang); $newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->thirdparty->default_lang);
$outputlangs->setDefaultLang($newlang); $outputlangs->setDefaultLang($newlang);
@ -475,13 +480,18 @@ else if ($action == 'add' && $user->rights->propal->creer) {
header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $id); header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $id);
exit(); exit();
} else {
$db->rollback();
} }
} else { else
dol_print_error($db, $object->error); {
$db->rollback(); $db->rollback();
exit(); $action='create';
}
}
else
{
setEventMessages($object->error, $object->errors, 'errors');
$db->rollback();
$action='create';
} }
} }
} }

View File

@ -870,14 +870,14 @@ class Propal extends CommonObject
} }
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->lasterror();
$error++; $error++;
} }
} }
} }
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->lasterror();
$error++; $error++;
} }
@ -895,7 +895,7 @@ class Propal extends CommonObject
} }
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->lasterror();
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }

View File

@ -1559,7 +1559,7 @@ if ($action == 'create' && $user->rights->commande->creer) {
} }
// Other attributes // 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 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by
// hook // hook
if (empty($reshook) && ! empty($extrafields->attribute_label)) { if (empty($reshook) && ! empty($extrafields->attribute_label)) {

View File

@ -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 $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(); $totalpaye = $facture_source->getSommePaiement();
$totalcreditnotes = $facture_source->getSumCreditNotesUsed(); $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
$totaldeposits = $facture_source->getSumDepositsUsed(); $totaldeposits = $facture_source->getSumDepositsUsed();
@ -1063,7 +1064,7 @@ else if ($action == 'add' && $user->rights->facture->creer)
$action = 'create'; $action = 'create';
$_GET["origin"] = $_POST["origin"]; $_GET["origin"] = $_POST["origin"];
$_GET["originid"] = $_POST["originid"]; $_GET["originid"] = $_POST["originid"];
setEventMessage($object->error, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
} }
} }

View File

@ -3460,6 +3460,7 @@ abstract class CommonObject
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db); $interface=new Interfaces($this->db);
$result=$interface->run_triggers($trigger_name,$this,$user,$langs,$conf); $result=$interface->run_triggers($trigger_name,$this,$user,$langs,$conf);
if ($result < 0) if ($result < 0)
{ {
if (!empty($this->errors)) if (!empty($this->errors))
@ -3471,6 +3472,7 @@ abstract class CommonObject
$this->errors=$interface->errors; $this->errors=$interface->errors;
} }
} }
return $result; return $result;
} }