Compare commits

..

2 commits

Author SHA1 Message Date
Benjamin Renard
24e3101dd0
Tpl: add fetch() method 2023-02-27 18:58:31 +01:00
Benjamin Renard
3742ce7448
Tpl::display(): add success event info on success hook and fix triggering it (and sentry span finish) on error 2023-02-27 18:53:40 +01:00

View file

@ -432,16 +432,56 @@ class Tpl {
} }
catch (Exception $e) { catch (Exception $e) {
Log :: exception($e, "Smarty - An exception occured displaying template '$template'"); Log :: exception($e, "Smarty - An exception occured displaying template '$template'");
Hook :: trigger('after_displaying_template', array('success' => false));
$sentry_span->finish();
if ($template != 'fatal_error.tpl') if ($template != 'fatal_error.tpl')
Log :: fatal(I18n::_("An error occurred while displaying this page.")); Log :: fatal(I18n::_("An error occurred while displaying this page."));
return; return;
} }
self :: purge_errors(); self :: purge_errors();
self :: purge_messages(); self :: purge_messages();
Hook :: trigger('after_displaying_template'); Hook :: trigger('after_displaying_template', array('success' => true));
$sentry_span->finish(); $sentry_span->finish();
} }
/**
* Fetch a template
* @param string $template The template to fetch
* @param string|null $pagetitle The page title (optional)
* @param array $extra_args Extra arguments to use to compute the page title using sprintf
* @return string|false
*/
public static function fetch($template, $pagetitle=null, ...$extra_args) {
if (!$template) {
Log :: warning("Tpl::fetch(): No template specified.");
return false;
}
$sentry_span = new SentrySpan('smarty.fetch_template', "Fetch Smarty template");
// If extra arguments passed, format pagetitle using sprintf
if ($pagetitle && $extra_args) {
$pagetitle = call_user_func_array(
'sprintf',
array_merge(array($pagetitle), $extra_args)
);
}
$result = false;
$success = false;
try {
Hook :: trigger('before_fetching_template');
self :: define_common_variables($pagetitle);
$result = self :: $smarty->fetch("Tpl:$template");
$success = true;
}
catch (Exception $e) {
Log :: exception($e, "Smarty - An exception occured fetching template '$template'");
}
Hook :: trigger('after_fetching_template', array('success' => $success));
$sentry_span->finish();
return $success?$result:false;
}
/** /**
* Display AJAX return * Display AJAX return
* @param array|null $data AJAX returned data (optional) * @param array|null $data AJAX returned data (optional)