Fixes packageDir in Template objects read via TemplateList
authorMatthias Schmidt <gravatronics@live.com>
Wed, 18 Dec 2013 17:59:04 +0000 (18:59 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Wed, 18 Dec 2013 17:59:04 +0000 (18:59 +0100)
Fixes #1594

wcfsetup/install/files/lib/data/template/TemplateList.class.php

index c51d8fc5cafac1917dcd4a50bfd608db46884d8e..59389317065c3f92264068c7f42481383ca58335 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 namespace wcf\data\template;
+use wcf\data\package\PackageCache;
 use wcf\data\DatabaseObjectList;
+use wcf\system\application\ApplicationHandler;
 
 /**
  * Represents a list of templates.
@@ -24,8 +26,29 @@ class TemplateList extends DatabaseObjectList {
        public function __construct() {
                parent::__construct();
                
-               $this->sqlSelects = 'package.package, package.packageDir, template_group.templateGroupFolderName';
+               $this->sqlSelects = 'package.package, template_group.templateGroupFolderName';
                $this->sqlJoins = " LEFT JOIN wcf".WCF_N."_package package ON (package.packageID = template.packageID)";
                $this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_template_group template_group ON (template_group.templateGroupID = template.templateGroupID)";
        }
+       
+       /**
+        * @see \wcf\data\DatabaseObjectList::readObjects()
+        */
+       public function readObjects() {
+               parent::readObjects();
+               
+               foreach ($this->objects as $template) {
+                       if ($template->application != 'wcf') {
+                               $application = ApplicationHandler::getInstance()->getApplication($template->application);
+                       }
+                       else {
+                               $application = ApplicationHandler::getInstance()->getWCF();
+                       }
+                       $package = PackageCache::getInstance()->getPackage($application->packageID);
+                       
+                       // set directory of the application package the template
+                       // belongs to
+                       $template->packageDir = $package->packageDir;
+               }
+       }
 }