From 16d60d54fd8f8d40a0a5ac1d8db0984716c24814 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Sat, 20 Apr 2013 23:07:11 +0200 Subject: [PATCH] Flush all caches after changing CACHE_SOURCE_TYPE Fixes #645 --- .../lib/data/option/OptionEditor.class.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/wcfsetup/install/files/lib/data/option/OptionEditor.class.php b/wcfsetup/install/files/lib/data/option/OptionEditor.class.php index 02b119889f..c60ad80af9 100644 --- a/wcfsetup/install/files/lib/data/option/OptionEditor.class.php +++ b/wcfsetup/install/files/lib/data/option/OptionEditor.class.php @@ -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(); + }); + } } /** -- 2.20.1