Skip to content

Commit

Permalink
Merge branch 'master' of github.com:LimeSurvey/LimeSurvey
Browse files Browse the repository at this point in the history
* 'master' of github.com:LimeSurvey/LimeSurvey:
  Dev: Check so that template is an object
  Fixed issue: Missing vanilla and fruity theme configuration after upgrading from 2.73
  Dev: Throw exception if installed theme is not installed.
  Dev: PHPDocs
  • Loading branch information
Shnoulle committed Jan 15, 2018
2 parents 06de295 + b7ef20f commit cbbe2bd
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 9 deletions.
2 changes: 1 addition & 1 deletion application/config/version.php
Expand Up @@ -13,7 +13,7 @@


$config['versionnumber'] = '3.0.3'; //The current version of this branch, LS3
$config['dbversionnumber'] = 343;
$config['dbversionnumber'] = 344;
$config['buildnumber'] = '';
$config['updatable'] = true;
$config['assetsversionnumber'] = '30004';
Expand Down
3 changes: 1 addition & 2 deletions application/core/LSETwigViewRenderer.php
Expand Up @@ -238,12 +238,11 @@ public function convertTwigToHtml($sString, $aDatas, $oTemplate)
* Find which template should be used to render a given view
* @param string $sView the view (layout) to render
* @param Template $oRTemplate the template where the custom option page should be looked for
* @return Template
* @return Template|boolean
*/
private function getTemplateForView($sView, $oRTemplate)
{
while (!file_exists($oRTemplate->viewPath.$sView)) {

$oMotherTemplate = $oRTemplate->oMotherTemplate;
if (!($oMotherTemplate instanceof TemplateConfiguration)) {
return false;
Expand Down
76 changes: 76 additions & 0 deletions application/helpers/update/updatedb_helper.php
Expand Up @@ -946,6 +946,82 @@ function db_upgrade_all($iOldDBVersion, $bSilent = false)
$oTransaction->commit();
}

/**
* Fix missing database values for templates after updating
* from 2.7x.
*/
if ($iOldDBVersion < 344) {
$oTransaction = $oDB->beginTransaction();

// All templates should inherit from vanilla as default (if extends is empty).
$oDB->createCommand()->update(
'{{templates}}',
[
'extends' => 'vanilla',
],
"extends=''"
);

// If vanilla template is missing, install it.
$vanilla = $oDB
->createCommand()
->select('*')
->from('{{templates}}')
->where('name=:name', ['name'=>'vanilla'])
->queryRow();
if (empty($vanilla)) {
$vanillaData = [
'name' => 'vanilla',
'folder' => 'vanilla',
'title' => 'Vanilla Theme',
'creation_date' => date('Y-m-d H:i:s'),
'author' =>'Louis Gac',
'author_email' => 'louis.gac@limesurvey.org',
'author_url' => 'https://www.limesurvey.org/',
'copyright' => 'Copyright (C) 2007-2017 The LimeSurvey Project Team\\r\\nAll rights reserved.',
'license' => 'License: GNU/GPL License v2 or later, see LICENSE.php\\r\\n\\r\\nLimeSurvey is free software. This version may have been modified pursuant to the GNU General Public License, and as distributed it includes or is derivative of works licensed under the GNU General Public License or other free or open source software licenses. See COPYRIGHT.php for copyright notices and details.',
'version' => '3.0',
'api_version' => '3.0',
'view_folder' => 'views',
'files_folder' => 'files',
'description' => '<strong>LimeSurvey Bootstrap Vanilla Survey Theme</strong><br>A clean and simple base that can be used by developers to create their own Bootstrap based theme.',
'last_update' => null,
'owner_id' => 1,
'extends' => '',
];
$oDB->createCommand()->insert('{{templates}}', $vanillaData);
}
$vanillaConf = $oDB
->createCommand()
->select('*')
->from('{{template_configuration}}')
->where('template_name=:template_name', ['template_name'=>'vanilla'])
->queryRow();
if (empty($vanillaConf)) {
$vanillaConfData = [
'template_name' => 'vanilla',
'sid' => NULL,
'gsid' => NULL,
'uid' => NULL,
'files_css' => '{"add":["css/ajaxify.css","css/theme.css","css/custom.css"]}',
'files_js' => '{"add":["scripts/theme.js","scripts/ajaxify.js","scripts/custom.js"]}',
'files_print_css' => '{"add":["css/print_theme.css"]}',
'options' => '{"ajaxmode":"on","brandlogo":"on","container":"on","brandlogofile":"./files/logo.png","font":"noto"}',
'cssframework_name' => 'bootstrap',
'cssframework_css' => '{}',
'cssframework_js' => '',
'packages_to_load' => '{"add":["pjax","font-noto"]}',
'packages_ltr' => NULL,
'packages_rtl' => NULL
];
$oDB->createCommand()->insert('{{template_configuration}}', $vanillaConfData);
}

$oDB->createCommand()->update('{{settings_global}}', ['stg_value'=>344], "stg_name='DBVersion'");
$oTransaction->commit();
}


} catch (Exception $e) {
Yii::app()->setConfig('Updating', false);
$oTransaction->rollback();
Expand Down
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 (is_object($oTemplate) && $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

0 comments on commit cbbe2bd

Please sign in to comment.