Skip to content

Commit

Permalink
Task #CR-1070: implement version validation checks for surveytheme/ad…
Browse files Browse the repository at this point in the history
…mintheme and display errors to the user
  • Loading branch information
ptelu committed Jun 12, 2023
1 parent 0bc1d54 commit e7bbeb8
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
39 changes: 35 additions & 4 deletions application/models/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,45 @@ public function checkExtendsItSelf()

/**
* Check if a given Template has a valid XML File
* @TODO: check api version
*
* @param string $sTemplateFolder the template forder name where to look for the XML
* @param string $templateName the template name
* @param string $templateFolder the template folder name where to look for the XML
* @return boolean
* @throws CDbException
*/
public static function checkTemplateXML($sTemplateFolder)
public static function checkTemplateXML($templateName, $templateFolder)
{
return (is_file(Yii::app()->getConfig("userthemerootdir") . DIRECTORY_SEPARATOR . $sTemplateFolder . DIRECTORY_SEPARATOR . 'config.xml') || is_file(Yii::app()->getConfig("standardthemerootdir") . DIRECTORY_SEPARATOR . $sTemplateFolder . DIRECTORY_SEPARATOR . 'config.xml'));
// check if the configuration can be found
$userThemePath = App()->getConfig("userthemerootdir") . DIRECTORY_SEPARATOR . $templateFolder . DIRECTORY_SEPARATOR . 'config.xml';
$standardThemePath = App()->getConfig("standardthemerootdir") . DIRECTORY_SEPARATOR . $templateFolder . DIRECTORY_SEPARATOR . 'config.xml';
if (is_file($userThemePath)) {
$currentThemePath = $userThemePath;
} elseif (is_file($standardThemePath)) {
$currentThemePath = $standardThemePath;
} else {
return false;
}

// check compatability with current limesurvey version
$extensionConfig = ExtensionConfig::loadFromFile($currentThemePath);
if ($extensionConfig === null) {
return false;
}
if (!$extensionConfig->isCompatible()) {
// TODO: write recursiveuninstall for childthemes
$extendedTemplates = (new Template)->findAll('extends = :templateName', [':templatename' => $templateName]);
if (!empty($extendedTemplates)) {
foreach ($extendedTemplates as $extendedTemplate) {
TemplateConfig::uninstall($extendedTemplate->name);
}
}

TemplateConfig::uninstall($templateName);
return false;
}

// all checks succeeded, continue loading the theme
return true;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions themes/survey/bootswatch/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<extends>vanilla</extends>
</metadata>

<compatibility>
<version>6.0</version>
</compatibility>

<!--
Here the list of the css/js files to add to the template package.
About packages in Yii: http://www.yiiframework.com/doc/api/1.1/CClientScript#packages-detail
Expand Down
4 changes: 4 additions & 0 deletions themes/survey/fruity/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<extends>vanilla</extends>
</metadata>

<compatibility>
<version>6.0</version>
</compatibility>

<!--
Here the list of the css/js files to add to the template package.
About packages in Yii: http://www.yiiframework.com/doc/api/1.1/CClientScript#packages-detail
Expand Down
5 changes: 4 additions & 1 deletion themes/survey/ls6_surveytheme/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<lastUpdate>2023-03-15 12:00:00</lastUpdate>
</metadata>

<compatibility>
<version>6.0</version>
</compatibility>

<!--
Here the list of the css/js files to add to the template package.
About packages in Yii: http://www.yiiframework.com/doc/api/1.1/CClientScript#packages-detail
Expand Down Expand Up @@ -152,7 +156,6 @@
</dropdownoptions>
</font>
<cssframework type="dropdown" category="Simple options" width="12" title="Variations" parent="cssframework">
apple
<dropdownoptions>
<option data-value="css/variations/theme_apple.css" value="apple">Apple</option>
<option data-value="css/variations/theme_blueberry.css" value="blueberry">Blueberry</option>
Expand Down
4 changes: 4 additions & 0 deletions themes/survey/vanilla/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
<lastUpdate>2021-06-26 17:00:00</lastUpdate>
</metadata>

<compatibility>
<version>6.0</version>
</compatibility>

<!--
Here the list of the css/js files to add to the template package.
About packages in Yii: http://www.yiiframework.com/doc/api/1.1/CClientScript#packages-detail
Expand Down

0 comments on commit e7bbeb8

Please sign in to comment.