Skip to content

Commit

Permalink
Dev: added a cache for templateNameFilter (called multiple times from…
Browse files Browse the repository at this point in the history
… admin)
  • Loading branch information
LouisGac committed Dec 21, 2017
1 parent 2ad3b37 commit fc6239d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion application/models/Template.php
Expand Up @@ -51,6 +51,9 @@ class Template extends LSActiveRecord
/** @var array $aTemplatesFileFolder cache for the method getTemplateFilesFolder */
public static $aTemplatesFileFolder = null;

/** @var array $aNamesFiltered cache for the method templateNameFilter */
public static $aNamesFiltered = null;

/** @var Template - The instance of template object */
private static $instance;

Expand Down Expand Up @@ -142,14 +145,20 @@ public function primaryKey()
*/
public static function templateNameFilter($sTemplateName)
{
// If the names has already been filtered, we skip the process
if (!empty(self::$aNamesFiltered[$sTemplateName])){
return self::$aNamesFiltered[$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') || is_file( Yii::app()->getConfig("standardthemerootdir").DIRECTORY_SEPARATOR.$oTemplate->folder.DIRECTORY_SEPARATOR.'config.xml') )) {
return $sTemplateName;
self::$aNamesFiltered[$sTemplateName] = $sTemplateName;
return self::$aNamesFiltered[$sTemplateName];
}

/* Then try with the global default template */
Expand All @@ -164,6 +173,7 @@ public static function templateNameFilter($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), 'error');
self::$aNamesFiltered[$sTemplateName] = $sTemplateName;
return $sTemplateName;
}else{
throw new Exception('No survey theme installed !!!!');
Expand Down

1 comment on commit fc6239d

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's not a cache, it's a static :) . cache is global

Please sign in to comment.