Navigation Menu

Skip to content

Commit

Permalink
Dev: Throw exception if theme extends it self (TODO: Show alert so us…
Browse files Browse the repository at this point in the history
…er can repair)
  • Loading branch information
olleharstedt committed Jan 16, 2018
1 parent f11c047 commit bff5e7e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
23 changes: 22 additions & 1 deletion application/models/Template.php
Expand Up @@ -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.
*/
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion application/models/TemplateConfiguration.php
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit bff5e7e

Please sign in to comment.