Fixed updating/deleting template groups incorrectly ignoring applications
authorAlexander Ebert <ebert@woltlab.com>
Mon, 9 Feb 2015 09:57:58 +0000 (10:57 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 9 Feb 2015 09:57:58 +0000 (10:57 +0100)
wcfsetup/install/files/lib/data/template/group/TemplateGroupEditor.class.php

index 79428e403714943d27dc4f1f31fc0b393ff26aca..5433cb0e0f4f5ebd29a0e28f4622f28242b6a84d 100644 (file)
@@ -2,14 +2,17 @@
 namespace wcf\data\template\group;
 use wcf\data\DatabaseObjectEditor;
 use wcf\data\IEditableCachedObject;
+use wcf\data\package\PackageCache;
+use wcf\system\application\ApplicationHandler;
 use wcf\system\cache\builder\TemplateGroupCacheBuilder;
+use wcf\system\WCF;
 use wcf\util\DirectoryUtil;
 
 /**
  * Provides functions to edit template groups.
  * 
  * @author     Marcel Werk
- * @copyright  2001-2014 WoltLab GmbH
+ * @copyright  2001-2015 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    com.woltlab.wcf
  * @subpackage data.template.group
@@ -29,6 +32,20 @@ class TemplateGroupEditor extends DatabaseObjectEditor implements IEditableCache
                
                if (isset($parameters['templateGroupFolderName']) && ($parameters['templateGroupFolderName'] != $this->templateGroupFolderName)) {
                        @rename(WCF_DIR . 'templates/' . $this->templateGroupFolderName, WCF_DIR . 'templates/' . $parameters['templateGroupFolderName']);
+                       
+                       // check template group folders in other applications
+                       $sql = "SELECT  DISTINCT application
+                               FROM    wcf".WCF_N."_template
+                               WHERE   templateGroupID = ?
+                                       AND application <> ?";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute(array($this->templateGroupID, 'wcf'));
+                       while ($row = $statement->fetchArray()) {
+                               $application = ApplicationHandler::getInstance()->getApplication($row['application']);
+                               $package = PackageCache::getInstance()->getPackage($application->packageID);
+                               
+                               @rename(WCF_DIR . $package->packageDir . 'templates/' . $this->templateGroupFolderName, WCF_DIR . $package->packageDir . 'templates/' . $parameters['templateGroupFolderName']);
+                       }
                }
        }
        
@@ -54,6 +71,22 @@ class TemplateGroupEditor extends DatabaseObjectEditor implements IEditableCache
                if (file_exists(WCF_DIR . 'templates/' . $this->templateGroupFolderName)) {
                        DirectoryUtil::getInstance(WCF_DIR . 'templates/' . $this->templateGroupFolderName)->removeAll();
                }
+               
+               // check template group folders in other applications
+               $sql = "SELECT  DISTINCT application
+                       FROM    wcf".WCF_N."_template
+                       WHERE   templateGroupID = ?
+                               AND application <> ?";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute(array($this->templateGroupID, 'wcf'));
+               while ($row = $statement->fetchArray()) {
+                       $application = ApplicationHandler::getInstance()->getApplication($row['application']);
+                       $package = PackageCache::getInstance()->getPackage($application->packageID);
+                       
+                       if (file_exists(WCF_DIR . $package->packageDir . 'templates/' . $this->templateGroupFolderName)) {
+                               DirectoryUtil::getInstance(WCF_DIR . $package->packageDir . 'templates/' . $this->templateGroupFolderName)->removeAll();
+                       }
+               }
        }
        
        /**