From 5fd6c44640571ef6c0d0441864c82d65e02af432 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 31 Aug 2015 13:00:24 +0200 Subject: [PATCH] Fix error management --- htdocs/comm/askpricesupplier/card.php | 2 +- htdocs/comm/propal.php | 2 +- htdocs/commande/card.php | 2 +- htdocs/compta/facture.php | 9 +++------ htdocs/core/class/commonobject.class.php | 11 ++++++++++- htdocs/expedition/card.php | 2 +- htdocs/fourn/facture/card.php | 4 ++-- 7 files changed, 19 insertions(+), 13 deletions(-) diff --git a/htdocs/comm/askpricesupplier/card.php b/htdocs/comm/askpricesupplier/card.php index 3fe244c7396..51368cb09a7 100644 --- a/htdocs/comm/askpricesupplier/card.php +++ b/htdocs/comm/askpricesupplier/card.php @@ -1761,7 +1761,7 @@ if ($action == 'create') $result = $object->generateDocument(GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); if ($result <= 0) { - dol_print_error($db, $result); + dol_print_error($db, $object->error, $object->errors); exit(); } $fileparams = dol_most_recent_file($conf->askpricesupplier->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+'); diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 4b9f84553ce..5c3b77fc391 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -2327,7 +2327,7 @@ if ($action == 'create') if (! $file || ! is_readable($file)) { $result = $object->generateDocument(GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); if ($result <= 0) { - dol_print_error($db, $result); + dol_print_error($db, $object->error, $object->errors); exit(); } $fileparams = dol_most_recent_file($conf->propal->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+'); diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 5c860eee1f6..bd76ec1646d 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -2360,7 +2360,7 @@ if ($action == 'create' && $user->rights->commande->creer) if (! $file || ! is_readable($file)) { $result = $object->generateDocument(GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); if ($result <= 0) { - dol_print_error($db, $result); + dol_print_error($db, $object->error, $object->errors); exit(); } $fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+'); diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 927819843a4..33734d2a84b 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -442,7 +442,7 @@ if (empty($reshook)) $ret = $object->fetch($id); // Reload to get new records $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - if ($result < 0) dol_print_error($db,$result); + if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } } else @@ -1421,10 +1421,7 @@ if (empty($reshook)) $ret = $object->fetch($id); // Reload to get new records $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - if ($result < 0) - { - setEventMessages($object->error, $object->errors, 'errors'); - } + if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } unset($_POST['prod_entry_mode']); @@ -3809,7 +3806,7 @@ else if ($id > 0 || ! empty($ref)) if (! $file || ! is_readable($file)) { $result = $object->generateDocument(GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); if ($result <= 0) { - dol_print_error($db, $result); + dol_print_error($db, $object->error, $object->errors); exit(); } $fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+'); diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index ed80a152665..a4136d880f0 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3470,11 +3470,20 @@ abstract class CommonObject if (empty($srctemplatepath)) { - $this->error='ErrorGenerationAskedForOdtTemplateWithNoSrcFileFound'; + $this->error='ErrorGenerationAskedForOdtTemplateWithSrcFileNotDefined'; return -1; } } + if ($obj->type == 'odt' && ! empty($srctemplatepath)) + { + if (! dol_is_file($srctemplatepath)) + { + $this->error='ErrorGenerationAskedForOdtTemplateWithSrcFileNotFound'; + return -1; + } + } + // We save charset_output to restore it because write_file can change it if needed for // output format that does not support UTF8. $sav_charset_output=$outputlangs->charset_output; diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index e72af4de601..1b871136235 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -1597,7 +1597,7 @@ else if ($id || $ref) $result = $object->generateDocument(GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); if ($result <= 0) { - dol_print_error($db,$result); + dol_print_error($db,$object->error,$object->errors); exit; } $fileparams = dol_most_recent_file($conf->expedition->dir_output . '/sending/' . $ref, preg_quote($ref, '/').'[^\-]+'); diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 38d11843714..6032a7a5036 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -526,7 +526,7 @@ if (empty($reshook)) $result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); if ($result <= 0) { - dol_print_error($db,$result); + dol_print_error($db,$object->error,$object->errors); exit; } } @@ -2296,7 +2296,7 @@ else $result = $object->generateDocument(GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); if ($result <= 0) { - dol_print_error($db,$result); + dol_print_error($db,$object->error,$object->errors); exit; } $fileparams = dol_most_recent_file($conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2,0,0,$object,'invoice_supplier').$ref, preg_quote($ref,'/').'([^\-])+');