Fixed last modification time of templates
authorMarcel Werk <burntime@woltlab.com>
Thu, 25 Apr 2013 23:33:02 +0000 (01:33 +0200)
committerMarcel Werk <burntime@woltlab.com>
Thu, 25 Apr 2013 23:33:02 +0000 (01:33 +0200)
wcfsetup/install/files/lib/system/package/TemplatesFileHandler.class.php

index 431071c47999ee8f1e1277ad0ec620de30f67e33..3697cb651d6037a9449b3ee4ebf5a883a4d52c19 100644 (file)
@@ -1,11 +1,13 @@
 <?php
 namespace wcf\system\package;
+use wcf\system\database\util\PreparedStatementConditionBuilder;
+use wcf\system\WCF;
 
 /**
  * File handler implementation for the installation of template files.
  * 
- * @author     Benjamin Kunz
- * @copyright  2001-2012 WoltLab GmbH
+ * @author     Marcel Werk
+ * @copyright  2001-2013 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    com.woltlab.wcf
  * @subpackage system.package
@@ -16,4 +18,59 @@ class TemplatesFileHandler extends ACPTemplatesFileHandler {
         * @see wcf\system\package\ACPTemplatesFileHandler::$tableName
         */
        protected $tableName = 'template';
+       
+       /**
+        * @see wcf\system\setup\IFileHandler::logFiles()
+        */
+       public function logFiles(array $files) {
+               $packageID = $this->packageInstallation->getPackageID();
+       
+               // remove file extension
+               foreach ($files as &$file) {
+                       $file = preg_replace('~.tpl$~', '', $file);
+               }
+               unset($file);
+       
+               // get existing templates
+               $existingTemplates = $updateTemplateIDs = array();
+               $sql = "SELECT  templateName, templateID
+                       FROM    wcf".WCF_N."_template
+                       WHERE   packageID = ?
+                               AND templateGroupID IS NULL";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute(array($packageID));
+               while ($row = $statement->fetchArray()) {
+                       $existingTemplates[$row['templateName']] = $row['templateID'];
+               }
+       
+               // save new templates
+               $sql = "INSERT INTO     wcf".WCF_N."_template
+                                       (packageID, templateName, lastModificationTime)
+                       VALUES          (?, ?, ?)";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               foreach ($files as $file) {
+                       if (isset($existingTemplates[$file])) {
+                               $updateTemplateIDs[] = $existingTemplates[$file];
+                               continue;
+                       }
+                       
+                       $statement->execute(array(
+                               $packageID,
+                               $file,
+                               TIME_NOW
+                       ));
+               }
+               
+               if (!empty($updateTemplateIDs)) {
+                       // update old templates
+                       $conditionBuilder = new PreparedStatementConditionBuilder();
+                       $conditionBuilder->add('templateID IN (?)', array($updateTemplateIDs));
+                       
+                       $sql = "UPDATE  wcf".WCF_N."_template
+                               SET     lastModificationTime = ?
+                               ".$conditionBuilder;
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute(array_merge(array(TIME_NOW), $conditionBuilder->getParameters()));
+               }
+       }
 }