From: Tim Düsterhus Date: Mon, 15 Aug 2016 15:28:28 +0000 (+0200) Subject: Initialize EmailTemplateEngine lazily X-Git-Tag: 3.0.0_Beta_1~746 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=6f68d5f58d4cdcd72d1143f17a791b8ab2d524fd;p=GitHub%2FWoltLab%2FWCF.git Initialize EmailTemplateEngine lazily --- diff --git a/wcfsetup/install/files/lib/system/template/ACPTemplateEngine.class.php b/wcfsetup/install/files/lib/system/template/ACPTemplateEngine.class.php index c5ad9b4277..f8bbd3dd1a 100644 --- a/wcfsetup/install/files/lib/system/template/ACPTemplateEngine.class.php +++ b/wcfsetup/install/files/lib/system/template/ACPTemplateEngine.class.php @@ -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"); } /** diff --git a/wcfsetup/install/files/lib/system/template/EmailTemplateEngine.class.php b/wcfsetup/install/files/lib/system/template/EmailTemplateEngine.class.php index cf39da9253..89b2695d12 100644 --- a/wcfsetup/install/files/lib/system/template/EmailTemplateEngine.class.php +++ b/wcfsetup/install/files/lib/system/template/EmailTemplateEngine.class.php @@ -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(); } /** diff --git a/wcfsetup/install/files/lib/system/template/TemplateEngine.class.php b/wcfsetup/install/files/lib/system/template/TemplateEngine.class.php index e92e7f614e..6f950ab7d3 100755 --- a/wcfsetup/install/files/lib/system/template/TemplateEngine.class.php +++ b/wcfsetup/install/files/lib/system/template/TemplateEngine.class.php @@ -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'; } /**