From 689cfc36ebbc24a45d5664d0d831e304a251c41f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Mon, 3 Jun 2024 13:43:20 +0200 Subject: [PATCH] fix cti (#29812) * fix cti Dead catch - OdfException is never thrown in the try block. * Update json.lib.php --- htdocs/core/lib/json.lib.php | 1 - .../doc/doc_generic_asset_odt.modules.php | 72 +++++++++---------- 2 files changed, 36 insertions(+), 37 deletions(-) diff --git a/htdocs/core/lib/json.lib.php b/htdocs/core/lib/json.lib.php index 1463f730c99..68f8c1d1995 100644 --- a/htdocs/core/lib/json.lib.php +++ b/htdocs/core/lib/json.lib.php @@ -297,7 +297,6 @@ function dol_json_decode($json, $assoc = false) if ($out != '') { try { // @phan-suppress-next-line PhanPluginUnsafeEval - //print debug_print_backtrace(); eval('$array = '.$out.';'); // not secured but this is no mode used as php json lib is always expected to be loaded now. } catch (Exception $e) { $array = array(); diff --git a/htdocs/core/modules/asset/doc/doc_generic_asset_odt.modules.php b/htdocs/core/modules/asset/doc/doc_generic_asset_odt.modules.php index c8c81e07f33..23ec2c8a8d7 100644 --- a/htdocs/core/modules/asset/doc/doc_generic_asset_odt.modules.php +++ b/htdocs/core/modules/asset/doc/doc_generic_asset_odt.modules.php @@ -396,44 +396,44 @@ class doc_generic_asset_odt extends ModelePDFAsset } } // Replace tags of lines + $foundtagforlines = 1; try { - $foundtagforlines = 1; - try { - $listlines = $odfHandler->setSegment('lines'); - } catch (OdfExceptionSegmentNotFound $e) { - // We may arrive here if tags for lines not present into template - $foundtagforlines = 0; - dol_syslog($e->getMessage(), LOG_INFO); - } catch (OdfException $e) { - $foundtagforlines = 0; - dol_syslog($e->getMessage(), LOG_INFO); - } - if ($foundtagforlines) { - $linenumber = 0; - foreach ($object->lines as $line) { - $linenumber++; - $tmparray = $this->get_substitutionarray_lines($line, $outputlangs, $linenumber); - complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines"); - // Call the ODTSubstitutionLine hook - $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray, 'line'=>$line); - $reshook = $hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - foreach ($tmparray 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); - } - } - $listlines->merge(); - } - $odfHandler->mergeSegment($listlines); - } + $listlines = $odfHandler->setSegment('lines'); + } catch (OdfExceptionSegmentNotFound $e) { + // We may arrive here if tags for lines not present into template + $foundtagforlines = 0; + dol_syslog($e->getMessage(), LOG_INFO); } catch (OdfException $e) { - $this->error = $e->getMessage(); - dol_syslog($this->error, LOG_WARNING); - return -1; + $foundtagforlines = 0; + dol_syslog($e->getMessage(), LOG_INFO); + } + if ($foundtagforlines) { + $linenumber = 0; + foreach ($object->lines as $line) { + $linenumber++; + $tmparray = $this->get_substitutionarray_lines($line, $outputlangs, $linenumber); + complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines"); + // Call the ODTSubstitutionLine hook + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray, 'line'=>$line); + $reshook = $hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks + foreach ($tmparray 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); + } + } + $listlines->merge(); + } + try { + $odfHandler->mergeSegment($listlines); + } catch (OdfException $e) { + $this->error = $e->getMessage(); + dol_syslog($this->error, LOG_WARNING); + return -1; + } } // Replace labels translated