From e852abc3442474821231be8487671e497b096b73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 5 May 2017 13:23:02 +0200 Subject: [PATCH] Fallback to disabled cache in case template loading fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #13238 Signed-off-by: Michal Čihař --- libraries/Template.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/libraries/Template.php b/libraries/Template.php index 3af96a8973..715414f5c3 100644 --- a/libraries/Template.php +++ b/libraries/Template.php @@ -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';