From bff5e7e65ab0c3104f3950b7b3e40798f26fdcf5 Mon Sep 17 00:00:00 2001 From: Olle Haerstedt Date: Tue, 16 Jan 2018 12:18:47 +0100 Subject: [PATCH] Dev: Throw exception if theme extends it self (TODO: Show alert so user can repair) --- application/models/Template.php | 23 +++++++++++++++++++- application/models/TemplateConfiguration.php | 4 +++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/application/models/Template.php b/application/models/Template.php index 3a4bda3f382..8497d15c0df 100755 --- a/application/models/Template.php +++ b/application/models/Template.php @@ -198,11 +198,15 @@ public function checkTemplate() // Check that extended template is installed. $this->checkTemplateExtends(); + // A template should not extend it self. + $this->checkExtendsItSelf(); + return true; } /** - * Returns false if any of the extended templates are not installed; otherwise true. + * Throws exception if any of the extended templates are not installed; otherwise + * returns true. * @return boolean * @throws Exception if extended template is not installed. */ @@ -222,6 +226,23 @@ public function checkTemplateExtends() return true; } + /** + * @return boolean + * @throws Exception if name equals extends. + */ + public function checkExtendsItSelf() + { + if ($this->name == $this->extends) { + throw new Exception( + sprintf( + 'Error: The template %s extends it self', + $this->name + ) + ); + } + return true; + } + /** * Check if a given Template has a valid XML File * @TODO: check api version diff --git a/application/models/TemplateConfiguration.php b/application/models/TemplateConfiguration.php index 4d8aea3074e..23b0864d07d 100755 --- a/application/models/TemplateConfiguration.php +++ b/application/models/TemplateConfiguration.php @@ -751,7 +751,9 @@ protected function setMotherTemplates() { if (!empty($this->template->extends)) { $sMotherTemplateName = $this->template->extends; - $this->oMotherTemplate = TemplateConfiguration::getInstanceFromTemplateName($sMotherTemplateName)->prepareTemplateRendering($sMotherTemplateName, null); + $instance = TemplateConfiguration::getInstanceFromTemplateName($sMotherTemplateName); + $instance->template->checkTemplate(); + $this->oMotherTemplate = $instance->prepareTemplateRendering($sMotherTemplateName, null); } }