Skip to content

Commit

Permalink
Dev: improvement of templateNameFilter to avoid infinite loop if defa…
Browse files Browse the repository at this point in the history
…ult theme is not installed
  • Loading branch information
LouisGac committed Dec 21, 2017
1 parent 3e19035 commit 34ad097
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions application/models/Template.php 100644 → 100755
Expand Up @@ -142,18 +142,13 @@ public function primaryKey()
*/
public static function templateNameFilter($sTemplateName)
{
$sDefaultTemplate = Yii::app()->getConfig('defaulttheme');
$sTemplateName = empty($sTemplateName) ? $sDefaultTemplate : $sTemplateName;

/* Standard Template return it without testing */
if (self::isStandardTemplate($sTemplateName)) {
return $sTemplateName;
}
$sRequestedTemplate = $sTemplateName;
$sDefaultTemplate = getGlobalSetting('defaulttheme');

/* Validate if template is OK in user dir, DIRECTORY_SEPARATOR not needed "/" is OK */
$oTemplate = self::model()->findByPk($sTemplateName);

if (is_object($oTemplate) && is_file(Yii::app()->getConfig("userthemerootdir").DIRECTORY_SEPARATOR.$oTemplate->folder.DIRECTORY_SEPARATOR.'config.xml')) {
if (is_object($oTemplate) && ( is_file(Yii::app()->getConfig("userthemerootdir").DIRECTORY_SEPARATOR.$oTemplate->folder.DIRECTORY_SEPARATOR.'config.xml') || is_file( Yii::app()->getConfig("standardthemerootdir").DIRECTORY_SEPARATOR.$oTemplate->folder.DIRECTORY_SEPARATOR.'config.xml') )) {
return $sTemplateName;
}

Expand All @@ -162,8 +157,17 @@ public static function templateNameFilter($sTemplateName)
return self::templateNameFilter($sDefaultTemplate);
}

/* Last solution : hard encode the name of the default template here */
return 'fruity';
/* If we're here, then the default survey theme is not installed and must be changed */
$aTemplateList = self::getTemplateList();
$sTemplateName = key($aTemplateList);
if (!empty($sTemplateName)){
setGlobalSetting('defaulttheme', $sTemplateName);
$sDefaultTemplate = getGlobalSetting('defaulttheme');
Yii::app()->setFlashMessage(sprintf(gT("Default survey theme %s is not installed. Now %s is the new default survey theme"), $sRequestedTemplate, $sTemplateName));
return $sTemplateName;
}else{
throw new Exception('No survey theme installed !!!!');
}
}


Expand Down

1 comment on commit 34ad097

@Shnoulle
Copy link
Collaborator

@Shnoulle Shnoulle commented on 34ad097 Dec 21, 2017

Choose a reason for hiding this comment

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

Erreur interne du serveur
Can't render layout layout_survey_list.twig for template bootswatch. Template version in database is 1.0, but in config.xml it's 2.0. Please re-install the template.

Une erreur interne est apparue lorsque le serveur web traitait votre requete. Veuillez contacter the webmaster pour signaler ce problème.

Merci.

:( : https://testing.sondages.pro/develop/

Please sign in to comment.