From 77986d3d107d88adaaef2bb3eb6ac7ec186496aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Tue, 18 Jun 2024 15:47:46 +0200 Subject: [PATCH] fix dead catch in odt stock (#30059) --- .../doc/doc_generic_stock_odt.modules.php | 67 +++++++++---------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/htdocs/core/modules/stock/doc/doc_generic_stock_odt.modules.php b/htdocs/core/modules/stock/doc/doc_generic_stock_odt.modules.php index f8b2d981a13..4db3e9f93d2 100644 --- a/htdocs/core/modules/stock/doc/doc_generic_stock_odt.modules.php +++ b/htdocs/core/modules/stock/doc/doc_generic_stock_odt.modules.php @@ -1,7 +1,7 @@ * Copyright (C) 2012 Juanjo Menent - * Copyright (C) 2018 Frédéric France + * Copyright (C) 2018-2024 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -279,10 +279,6 @@ class doc_generic_stock_odt extends ModelePDFStock $filename = $newfiletmp . '.' . $newfileformat; } $file = $dir . '/' . $filename; - //print "newdir=".$dir; - //print "newfile=".$newfile; - //print "file=".$file; - //print "conf->product->dir_temp=".$conf->product->dir_temp; dol_mkdir($conf->product->dir_temp); if (!is_writable($conf->product->dir_temp)) { @@ -317,11 +313,11 @@ class doc_generic_stock_odt extends ModelePDFStock } // Make substitution $substitutionarray = array( - '__FROM_NAME__' => $this->emetteur->name, - '__FROM_EMAIL__' => $this->emetteur->email, - '__TOTAL_TTC__' => $object->total_ttc, - '__TOTAL_HT__' => $object->total_ht, - '__TOTAL_VAT__' => $object->total_tva + '__FROM_NAME__' => $this->emetteur->name, + '__FROM_EMAIL__' => $this->emetteur->email, + '__TOTAL_TTC__' => $object->total_ttc, + '__TOTAL_HT__' => $object->total_ht, + '__TOTAL_VAT__' => $object->total_tva ); complete_substitutions_array($substitutionarray, $langs, $object); // Call the ODTSubstitution hook @@ -355,8 +351,6 @@ class doc_generic_stock_odt extends ModelePDFStock // After construction $odfHandler->contentXml contains content and // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by // [!-- BEGIN lines --]*[!-- END lines --] - //print html_entity_decode($odfHandler->__toString()); - //print exit; $object->fetch_optionals(); @@ -370,7 +364,7 @@ class doc_generic_stock_odt extends ModelePDFStock // Define substitution array $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); $array_object_from_properties = $this->get_substitutionarray_each_var_object($object, $outputlangs); - //$array_objet=$this->get_substitutionarray_object($object,$outputlangs); + //$array_objet = $this->get_substitutionarray_object($object,$outputlangs); $array_user = $this->get_substitutionarray_user($user, $outputlangs); $array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs); $array_thirdparty = $this->get_substitutionarray_thirdparty($socobject, $outputlangs); @@ -404,32 +398,37 @@ class doc_generic_stock_odt extends ModelePDFStock } } // Replace tags of lines + $foundtagforlines = 1; try { $listlines = $odfHandler->setSegment('supplierprices'); - if (!empty($object->supplierprices)) { - foreach ($object->supplierprices as $supplierprice) { - $array_lines = $this->get_substitutionarray_each_var_object($supplierprice, $outputlangs); - complete_substitutions_array($array_lines, $outputlangs, $object, $supplierprice, "completesubstitutionarray_lines"); - // Call the ODTSubstitutionLine hook - $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$array_lines, 'line'=>$supplierprice); - $reshook = $hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - foreach ($array_lines as $key => $val) { - try { - $listlines->setVars($key, $val, true, 'UTF-8'); - } catch (OdfException $e) { - dol_syslog($e->getMessage(), LOG_INFO); - } catch (SegmentException $e) { - dol_syslog($e->getMessage(), LOG_INFO); - } + } catch (OdfExceptionSegmentNotFound $e) { + // We may arrive here if tags for lines not present into template + $foundtagforlines = 0; + dol_syslog($e->getMessage(), LOG_INFO); + } + if ($foundtagforlines && !empty($object->supplierprices)) { + foreach ($object->supplierprices as $supplierprice) { + $array_lines = $this->get_substitutionarray_each_var_object($supplierprice, $outputlangs); + complete_substitutions_array($array_lines, $outputlangs, $object, $supplierprice, "completesubstitutionarray_lines"); + // Call the ODTSubstitutionLine hook + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$array_lines, 'line'=>$supplierprice); + $reshook = $hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks + foreach ($array_lines as $key => $val) { + try { + $listlines->setVars($key, $val, true, 'UTF-8'); + } catch (SegmentException $e) { + dol_syslog($e->getMessage(), LOG_INFO); } - $listlines->merge(); } + $listlines->merge(); + } + try { + $odfHandler->mergeSegment($listlines); + } catch (OdfException $e) { + $this->error = $e->getMessage(); + dol_syslog($this->error, LOG_WARNING); + return -1; } - $odfHandler->mergeSegment($listlines); - } catch (OdfException $e) { - $this->error = $e->getMessage(); - dol_syslog($this->error, LOG_WARNING); - return -1; } // Replace labels translated