Initialize EmailTemplateEngine lazily
authorTim Düsterhus <duesterhus@woltlab.com>
Mon, 15 Aug 2016 15:28:28 +0000 (17:28 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Mon, 15 Aug 2016 15:28:28 +0000 (17:28 +0200)
wcfsetup/install/files/lib/system/template/ACPTemplateEngine.class.php
wcfsetup/install/files/lib/system/template/EmailTemplateEngine.class.php
wcfsetup/install/files/lib/system/template/TemplateEngine.class.php

index c5ad9b42776824310f085c708a316cd313eea204..f8bbd3dd1a4be9cada50c3c40b07c0f8c0992ff1 100644 (file)
@@ -50,15 +50,17 @@ class ACPTemplateEngine extends TemplateEngine {
                        $abbreviation = ApplicationHandler::getInstance()->getActiveApplication()->getAbbreviation();
                }
                
-               return $this->compileDir.$this->templateGroupID.'_'.$abbreviation.'_'.$this->languageID.'_'.$templateName.'.php';
+               return $this->compileDir.$this->getTemplateGroupID().'_'.$abbreviation.'_'.$this->languageID.'_'.$templateName.'.php';
        }
        
        /**
-        * @inheritDoc
+        * This method always throws, because changing the template group is not supported.
+        * 
+        * @param       integer         $templateGroupID
+        * @throws      \BadMethodCallException
         */
-       public final function setTemplateGroupID($templateGroupID) {
-               // template groups are not supported by the acp template engine
-               $this->templateGroupID = 0;
+       public function setTemplateGroupID($templateGroupID) {
+               throw new \BadMethodCallException("You may not change the template group of the acp template engine");
        }
        
        /**
index cf39da925326b5243f22b6704f5aa6a40a20a6bc..89b2695d12aea72a00be5b8e3773162d0dbca78c 100644 (file)
@@ -19,16 +19,20 @@ class EmailTemplateEngine extends TemplateEngine {
        /**
         * @inheritDoc
         */
-       protected function init() {
-               parent::init();
+       public function getTemplateGroupID() {
+               static $initialized = false;
                
-               $sql = "SELECT  templateGroupID
-                       FROM    wcf".WCF_N."_template_group
-                       WHERE   templateGroupFolderName = ?";
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(['_wcf_email/']);
+               if (!$initialized) {
+                       $sql = "SELECT  templateGroupID
+                               FROM    wcf".WCF_N."_template_group
+                               WHERE   templateGroupFolderName = ?";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute(['_wcf_email/']);
+                       
+                       parent::setTemplateGroupID($statement->fetchSingleColumn());
+               }
                
-               parent::setTemplateGroupID($statement->fetchSingleColumn());
+               return parent::getTemplateGroupID();
        }
        
        /**
index e92e7f614eee268ff6f6f22ae54aca46ee08788c..6f950ab7d34385743739e3af652347c4663ad2c0 100755 (executable)
@@ -359,7 +359,7 @@ class TemplateEngine extends SingletonFactory {
         * @return      string
         */
        protected function getPath($templatePath, $templateName) {
-               $templateGroupID = $this->templateGroupID;
+               $templateGroupID = $this->getTemplateGroupID();
                
                while ($templateGroupID != 0) {
                        $templateGroup = $this->templateGroupCache[$templateGroupID];
@@ -390,7 +390,7 @@ class TemplateEngine extends SingletonFactory {
         * @return      string
         */
        public function getCompiledFilename($templateName, $application) {
-               return $this->compileDir.$this->templateGroupID.'_'.$application.'_'.$this->languageID.'_'.$templateName.'.php';
+               return $this->compileDir.$this->getTemplateGroupID().'_'.$application.'_'.$this->languageID.'_'.$templateName.'.php';
        }
        
        /**
@@ -400,7 +400,7 @@ class TemplateEngine extends SingletonFactory {
         * @return      string
         */
        public function getMetaDataFilename($templateName) {
-               return $this->compileDir.$this->templateGroupID.'_'.$templateName.'.meta.php';
+               return $this->compileDir.$this->getTemplateGroupID().'_'.$templateName.'.meta.php';
        }
        
        /**