Fallback to disabled cache in case template loading fails

Fixes #13238

Signed-off-by: Michal Čihař <michal@cihar.com>
This commit is contained in:
Michal Čihař 2017-05-05 13:23:02 +02:00
parent 92a1e5a47b
commit e852abc344

View File

@ -174,8 +174,26 @@ class Template
if (file_exists($template . '.twig')) {
$this->set($data);
return $this->twig->load($this->name . '.twig')
->render($this->data);
try {
$template = $this->twig->load($this->name . '.twig');
} catch (\RuntimeException $e) {
/* Retry with disabled cache */
$this->twig->setCache(false);
$template = $this->twig->load($this->name . '.twig');
/*
* The trigger error is intentionally after second load
* to avoid triggering error when disabling cache does not
* solve it.
*/
trigger_error(
sprintf(
__('Error while working with template cache: %s'),
$e->getMessage()
),
E_USER_WARNING
);
}
return $template->render($this->data);
}
$template = $template . '.phtml';