Flush all caches after changing CACHE_SOURCE_TYPE
authorTim Düsterhus <duesterhus@woltlab.com>
Sat, 20 Apr 2013 21:07:11 +0000 (23:07 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Sat, 20 Apr 2013 21:07:43 +0000 (23:07 +0200)
Fixes #645

wcfsetup/install/files/lib/data/option/OptionEditor.class.php

index 02b119889f5ed2d0ca1e2a24968518fa255e92a6..c60ad80af95c26608474c6453da6b93fffc46ee7 100644 (file)
@@ -3,6 +3,7 @@ namespace wcf\data\option;
 use wcf\data\DatabaseObjectEditor;
 use wcf\data\IEditableCachedObject;
 use wcf\system\cache\builder\OptionCacheBuilder;
+use wcf\system\cache\CacheHandler;
 use wcf\system\io\File;
 use wcf\system\WCF;
 
@@ -60,12 +61,24 @@ class OptionEditor extends DatabaseObjectEditor implements IEditableCachedObject
         * @param       array           $options        id to value
         */
        public static function updateAll(array $options) {
+               $sql = "SELECT  optionID, optionValue
+                       FROM    wcf".WCF_N."_option
+                       WHERE   optionName = ?";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute(array('cache_source_type'));
+               $row = $statement->fetchArray();
+               
                $sql = "UPDATE  wcf".WCF_N."_option
                        SET     optionValue = ?
                        WHERE   optionID = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
                
+               $flushCache = false;
                foreach ($options as $id => $value) {
+                       if ($id == $row['optionID'] && ($value != $row['optionValue'] || $value != CACHE_SOURCE_TYPE) {
+                               $flushCache = true;
+                       }
+                       
                        $statement->execute(array(
                                $value,
                                $id
@@ -74,6 +87,17 @@ class OptionEditor extends DatabaseObjectEditor implements IEditableCachedObject
                
                // force a cache reset if options were changed
                self::resetCache();
+               
+               // flush entire cache, as the CacheSource was changed
+               if ($flushCache) {
+                       // flush caches (in case register_shutdown_function gets not properly called)
+                       CacheHandler::getInstance()->flushAll();
+                       
+                       // flush cache before finishing request to flush caches created after this was executed
+                       register_shutdown_function(function() {
+                               CacheHandler::getInstance()->flushAll();
+                       });
+               }
        }
        
        /**