Skip to content

Commit

Permalink
Dev: Throw exception if installed theme is not installed.
Browse files Browse the repository at this point in the history
Dev: This only happend during erroneous update.
  • Loading branch information
olleharstedt committed Jan 15, 2018
1 parent d46100a commit c8523a1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
45 changes: 43 additions & 2 deletions application/models/Template.php
Expand Up @@ -156,7 +156,7 @@ public static function templateNameFilter($sTemplateName)
/* Validate if template is OK in user dir, DIRECTORY_SEPARATOR not needed "/" is OK */
$oTemplate = self::model()->findByPk($sTemplateName);

if (is_object($oTemplate) && (self::checkTemplateXML($oTemplate->folder))) {
if ($oTemplate->checkTemplate() && (self::checkTemplateXML($oTemplate->folder))) {
self::$aNamesFiltered[$sTemplateName] = $sTemplateName;
return self::$aNamesFiltered[$sTemplateName];
}
Expand All @@ -168,7 +168,15 @@ public static function templateNameFilter($sTemplateName)

/* If we're here, then the default survey theme is not installed and must be changed */
$aTemplateList = self::model()->search()->getData();
$sTemplateName = $aTemplateList[0]->name;
$i = 0;
while ($sTemplateName == $sRequestedTemplate) {
if (!empty($aTemplateList[$i])) {
$sTemplateName = $aTemplateList[$i]->name;
} else {
throw new Exception('Could not find a working installed template');
}
$i++;
}

if (!empty($sTemplateName)) {
setGlobalSetting('defaulttheme', $sTemplateName);
Expand All @@ -181,6 +189,39 @@ public static function templateNameFilter($sTemplateName)
}
}

/**
* @return boolean
* @throws Exception if extended template is not installed.
*/
public function checkTemplate()
{
// Check that extended template is installed.
$this->checkTemplateExtends();

return true;
}

/**
* Returns false if any of the extended templates are not installed; otherwise true.
* @return boolean
* @throws Exception if extended template is not installed.
*/
public function checkTemplateExtends()
{
if (!empty($this->extends)) {
$oRTemplate = self::model()->findByPk($this->extends);
if (empty($oRTemplate)) {
throw new Exception(
sprintf(
'Extended template "%s" is not installed.',
$this->extends
)
);
}
}
return true;
}

/**
* Check if a given Template has a valid XML File
* @TODO: check api version
Expand Down
7 changes: 3 additions & 4 deletions application/models/TemplateConfiguration.php
Expand Up @@ -523,6 +523,7 @@ class='btn btn-default btn-block'>

//


$OptionLink = '';

if ($this->hasOptionPage) {
Expand All @@ -535,7 +536,6 @@ class='btn btn-default btn-block'>
</a>";
}


$sUninstallLink = '<a
id="remove_fromdb_link_'.$this->template_name.'"
data-href="'.$sUninstallUrl.'"
Expand Down Expand Up @@ -581,9 +581,8 @@ class="btn btn-danger btn-block"

public function getHasOptionPage()
{


$oRTemplate = $this->prepareTemplateRendering($this->template->name);
$filteredName = Template::templateNameFilter($this->template->name);
$oRTemplate = $this->prepareTemplateRendering($filteredName);

$sOptionFile = 'options'.DIRECTORY_SEPARATOR.'options.twig';
while (!file_exists($oRTemplate->path.$sOptionFile)) {
Expand Down

2 comments on commit c8523a1

@LouisGac
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why throwing an exception?
this prevents the user from logging in...
just show a nice error message please.
I revert it for now.

@olleharstedt
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, yeah.

Please sign in to comment.