From 7858ec10092071d595c3814264c537cd16695875 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Roland=20H=C3=A4der?= <roland@mxchange.org>
Date: Wed, 23 Jan 2013 20:37:06 +0000
Subject: [PATCH] Use rebuildCache() instead of
 loadCacheFile()/removeCacheFile()

---
 inc/classes/cachesystem.class.php     |  4 ++--
 inc/filter/cache_filter.php           | 19 +++++--------------
 inc/functions.php                     |  1 +
 inc/gen_sql_patches.php               |  9 +++------
 inc/modules/admin/what-extensions.php |  7 ++-----
 inc/mysql-manager.php                 |  9 ++++-----
 6 files changed, 17 insertions(+), 32 deletions(-)

diff --git a/inc/classes/cachesystem.class.php b/inc/classes/cachesystem.class.php
index 2408c751bc..d9cf3418a3 100644
--- a/inc/classes/cachesystem.class.php
+++ b/inc/classes/cachesystem.class.php
@@ -173,9 +173,9 @@ class CacheSystem {
 					$GLOBALS['cache_array']['config'][$data['config']][$k] = $v;
 				} elseif ($this->name == 'filter') {
 					// Filter
-					$GLOBALS['cache_array']['filter']['chains'][$data['filter_name']][$data['filter_function']] = $data['filter_active'];
+					$GLOBALS['cache_array']['filter']['chains'][$data['filter_name']][$data['filter_function']]  = $data['filter_active'];
 					$GLOBALS['cache_array']['filter']['counter'][$data['filter_name']][$data['filter_function']] = $data['filter_counter'];
-					$GLOBALS['cache_array']['filter']['loaded'][$data['filter_name']][$data['filter_function']] = TRUE;
+					$GLOBALS['cache_array']['filter']['loaded'][$data['filter_name']][$data['filter_function']]  = TRUE;
 				} elseif ($this->name == 'modules') {
 					// Modules
 					$GLOBALS['cache_array']['modules'][$k][$data['module']] = $v;
diff --git a/inc/filter/cache_filter.php b/inc/filter/cache_filter.php
index d675aa43be..706585fd49 100644
--- a/inc/filter/cache_filter.php
+++ b/inc/filter/cache_filter.php
@@ -50,11 +50,8 @@ function FILTER_CACHE_DESTROY_ON_EXT_CHANGE ($filterData) {
 
 	// Remove cache
 	foreach (array('config', 'extension', 'filter', 'modules', 'earning', 'points_data') as $cache) {
-		// Is this cache there?
-		if ($GLOBALS['cache_instance']->loadCacheFile($cache)) {
-			// Yes, then remove it
-			$GLOBALS['cache_instance']->removeCacheFile();
-		} // END - if
+		// Rebuild cache
+		rebuildCache($cache);
 	} // END - foreach
 
 	// Return it
@@ -71,9 +68,7 @@ function FILTER_CACHE_DESTROY_ON_ADMIN_CHANGE ($filterData) {
 	} // END - if
 
 	// Remove cache
-	if ($GLOBALS['cache_instance']->loadCacheFile('admin')) {
-		$GLOBALS['cache_instance']->removeCacheFile();
-	} // END - if
+	rebuildCache('admin');
 
 	// Return the data
 	//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
@@ -90,12 +85,8 @@ function FILTER_CACHE_DESTROY_ALL ($filterData) {
 
 	// Remove cache files
 	foreach (array('admin', 'admin_acls', 'config', 'extension', 'earning', 'filter', 'imprint', 'modules', 'payments', 'points_data', 'refdepths', 'refsystem', 'themes') as $cache) {
-		// Is the cache file readable?
-		// @TODO This should be rewritten not to load the cache file for just checking if it is there for save removal.
-		if ($GLOBALS['cache_instance']->loadCacheFile($cache)) {
-			// Remove the cache file
-			$GLOBALS['cache_instance']->removeCacheFile();
-		} // END - if
+		// Rebuild it
+		rebuildCache($cache);
 	} // END - foreach
 
 	//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
diff --git a/inc/functions.php b/inc/functions.php
index 857d2c41b2..02e0b7a5e8 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -1532,6 +1532,7 @@ function rebuildCache ($cache, $inc = '', $force = FALSE) {
 	// Shall I remove the cache file?
 	if ((isExtensionInstalled('cache')) && (isCacheInstanceValid()) && (isHtmlOutputMode())) {
 		// Rebuild cache only in HTML output-mode
+		// @TODO This should be rewritten not to load the cache file for just checking if it is there for save removal.
 		if ($GLOBALS['cache_instance']->loadCacheFile($cache)) {
 			// Destroy it
 			$GLOBALS['cache_instance']->removeCacheFile($force);
diff --git a/inc/gen_sql_patches.php b/inc/gen_sql_patches.php
index 783124e1b4..14158396a6 100644
--- a/inc/gen_sql_patches.php
+++ b/inc/gen_sql_patches.php
@@ -95,12 +95,9 @@ if (getFileHash() == '') {
 // @TODO Rewrite this to a filter
 if ((isExtensionInstalledAndNewer('cache', '0.1.2')) && (isCacheInstanceValid())) {
 	// Destroy some cache files
-	foreach (array('config', 'extension', 'filter', 'modules')  as $cache) {
-		// Is the cache file there?
-		if ($GLOBALS['cache_instance']->loadCacheFile($cache)) {
-			// Then remove it
-			$GLOBALS['cache_instance']->removeCacheFile();
-		} // END - if
+	foreach (array('config', 'extension', 'filter', 'modules') as $cache) {
+		// Use rebuildCache()
+		rebuildCache($cache);
 	} // END - foreach
 } // END - if
 
diff --git a/inc/modules/admin/what-extensions.php b/inc/modules/admin/what-extensions.php
index 233e9de414..c18bd86ca0 100644
--- a/inc/modules/admin/what-extensions.php
+++ b/inc/modules/admin/what-extensions.php
@@ -367,11 +367,8 @@ ORDER BY
 						if (isExtensionActive('cache')) {
 							// Remove cache file (will be auto-created again!)
 							foreach (array('config', 'extension', 'filter', 'modules') as $cache) {
-								// Is the cache file there?
-								if ($GLOBALS['cache_instance']->loadCacheFile($cache)) {
-									// Remove cache file
-									$GLOBALS['cache_instance']->removeCacheFile();
-								} // END - if
+								// Rebuild cache file
+								rebuildCache($cache);
 							} // END - foreach
 						} // END - if
 
diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php
index 28ba603cfe..394189cc9f 100644
--- a/inc/mysql-manager.php
+++ b/inc/mysql-manager.php
@@ -843,6 +843,8 @@ function getActionFromModuleWhat ($module, $what) {
 				$module,
 				$what
 			), __FUNCTION__, __LINE__);
+
+		// Entry found?
 		if (SQL_NUMROWS($result) == 1) {
 			// Load action value and pray that this one is the right you want... ;-)
 			$data = SQL_FETCHARRAY($result);
@@ -2281,11 +2283,8 @@ function doGenericEditEntriesConfirm ($tableName, $columns = array(), $filterFun
 				continue;
 			} // END - if
 
-			// Is the cache file loadable?
-			if ($GLOBALS['cache_instance']->loadCacheFile($cache)) {
-				// Then remove it
-				$GLOBALS['cache_instance']->removeCacheFile();
-			} // END - if
+			// Use rebuildCache() to delete it
+			rebuildCache($cache);
 		} // END - foreach
 	} // END - if
 
-- 
2.39.5