X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Flibs%2Fcache_functions.php;h=1c083863ec2e13a7dbf75d5f71d2148d5becaacd;hp=611073a72ae89cba3603f1129bd3f217afc0c64b;hb=39172de4ecec2f6ddc597a5ae439e7aef79c75ed;hpb=6586600d8020147192e5f28ca2a3a0153f774d3c
diff --git a/inc/libs/cache_functions.php b/inc/libs/cache_functions.php
index 611073a72a..1c083863ec 100644
--- a/inc/libs/cache_functions.php
+++ b/inc/libs/cache_functions.php
@@ -47,6 +47,7 @@ class CacheSystem {
var $data = "";
var $version = "";
var $name = "";
+ var $rebuilt = array();
// Constructor
function CacheSystem ($interval, $path, $tested) {
@@ -159,10 +160,8 @@ class CacheSystem {
// Remove pointer
$this->pointer = false;
- } else {
- // Cannot create file
- ADD_FATAL(__FILE__."(".__LINE__."): ".CACHE_PROBLEMS_DETECTED);
- }
+ //* DEBUG: */ print __METHOD__."(".__LINE__."): {$this->name} - FINALIZED!
\n";
+ } // END - if
}
function getArrayFromCache () {
@@ -213,17 +212,20 @@ class CacheSystem {
// Destroy an existing cache file
function destroyCacheFile () {
// Is the cache file there?
- if (FILE_READABLE($this->inc)) {
+ if ((!isset($this->rebuilt[$this->name])) && (FILE_READABLE($this->inc))) {
// Close cache
$this->finalize();
// Remove cache file from system
+ //* DEBUG: */ print __METHOD__."(".__LINE__."): {$this->name} - DESTROYED!
\n";
unlink($this->inc);
// Is the file there?
if (!FILE_READABLE($this->inc)) {
// The cache does no longer exist so kill the content
unset($this->data[$this->name]);
+ unset($this->version[$this->name]);
+ $this->rebuilt[$this->name] = true;
} else {
// Not removed!
ADD_FATAL(__FILE__."(".__LINE__."): ".CACHE_CANNOT_UNLINK_1.$this->inc.CACHE_CANNOT_UNLINK_2);
@@ -247,7 +249,7 @@ class CacheSystem {
foreach ($array as $a) {
// So we can remove all elements as requested
unset($dummy[$a][$key]);
- }
+ } // END - foreach
// Flush array to cache file
$this->init();
@@ -306,8 +308,8 @@ class CacheSystem {
if ($a == $search) {
// Update now...
$dummy[$a][$search_key] = $replace;
- }
- }
+ } // END - if
+ } // END - foreach
// Flush array to cache file
$this->init();
@@ -317,8 +319,8 @@ class CacheSystem {
// Close cache file
$this->finalize();
- }
- }
+ } // END - if
+ } // END - if
} else {
// Cannot write to cache!
ADD_FATAL(__FILE__."(".__LINE__."): ".CACHE_PROBLEMS_DETECTED);
@@ -333,6 +335,10 @@ class CacheSystem {
// Write cache line to file
fwrite($this->pointer, "\$cache_version['".$ext_name."'] = \"".$ext_ver."\";\n");
+
+ // Add the extension version to object (DO NOT REMOVE IT! Endless loop...)
+ $this->version[$this->name][$ext_name] = $ext_ver;
+ //* DEBUG: */ print __METHOD__."(".__LINE__."): {$this->name} - {$ext_name}={$ext_ver}
\n";
} else {
// Cannot create file
ADD_FATAL(__FILE__."(".__LINE__."): ".CACHE_PROBLEMS_DETECTED);
@@ -346,6 +352,14 @@ class CacheSystem {
// Get extension version
$ext_ver = GET_EXT_VERSION($ext_name);
+ // Debug messages
+ if (isset($this->version[$this->name][$ext_name])) {
+ //* DEBUG: */ print __METHOD__."(".__LINE__."): cache={$this->name},ext_name={$ext_name} - {$ext_ver}/{$this->version[$this->name][$ext_name]}
\n";
+ } else {
+ // No cache version found!
+ DEBUG_LOG(__METHOD__, __LINE__, "Cache {$this->name} has missing entry for extension {$ext_name}!");
+ }
+
// Compare both
return ((isset($this->version[$this->name][$ext_name])) && ($this->version[$this->name][$ext_name] == $ext_ver));
}
@@ -381,5 +395,53 @@ class CacheSystem {
return $this->ret;
}
}
+
+// Destroy the cache on extension changes
+function FILTER_CACHE_DESTROY_ON_EXT_CHANGE ($data) {
+ global $cacheInstance;
+
+ // Remove cache
+ if (EXT_IS_ACTIVE("cache")) {
+ if ($cacheInstance->loadCacheFile("config")) $cacheInstance->destroyCacheFile();
+ if ($cacheInstance->loadCacheFile("extensions")) $cacheInstance->destroyCacheFile();
+ if ($cacheInstance->loadCacheFile("mod_reg")) $cacheInstance->destroyCacheFile();
+ } // END - if
+
+ // Return it
+ return $DATA;
+}
+
+// Destroy the cache on changing admin
+function FILTER_CACHE_DESTROY_ON_ADMIN_CHANGE () {
+ global $cacheInstance;
+
+ // Remove cache
+ if (EXT_IS_ACTIVE("cache")) {
+ if ($cacheInstance->loadCacheFile("admins")) $cacheInstance->destroyCacheFile();
+ } // END - if
+}
+
+// Destroy all cache files
+function FILTER_CACHE_DESTROY_ALL () {
+ global $cacheInstance;
+
+ // Remove cache
+ if (EXT_IS_ACTIVE("cache")) {
+ if ($cacheInstance->loadCacheFile("admins")) $cacheInstance->destroyCacheFile();
+ if ($cacheInstance->loadCacheFile("config")) $cacheInstance->destroyCacheFile();
+ if ($cacheInstance->loadCacheFile("extensions")) $cacheInstance->destroyCacheFile();
+ if ($cacheInstance->loadCacheFile("mod_reg")) $cacheInstance->destroyCacheFile();
+ if ($cacheInstance->loadCacheFile("refdepths")) $cacheInstance->destroyCacheFile();
+ if ($cacheInstance->loadCacheFile("refsystem")) $cacheInstance->destroyCacheFile();
+ if ($cacheInstance->loadCacheFile("themes")) $cacheInstance->destroyCacheFile();
+ } // END - if
+}
+
+// Filter for purging entire admin menu cache
+function FILTER_CACHE_PURGE_ADMIN_MENU () {
+ // Just call the function
+ CACHE_PURGE_ADMIN_MENU();
+}
+
//
?>