X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Flibs%2Fcache_functions.php;h=bb5db58000437a062c22366339b8590ab85638f6;hp=bb24447efda1ab67f3b79ec8dd00bbce66048dec;hb=56156f6c4392510cdbe0eb4f2ccefc23b43e2672;hpb=8fcf84db9fb67ecc531962b23811330d5cd07a91
diff --git a/inc/libs/cache_functions.php b/inc/libs/cache_functions.php
index bb24447efd..bb5db58000 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) {
@@ -111,7 +112,7 @@ class CacheSystem {
$this->storeExtensionVersion("cache");
} else {
// Cannot create file
- ADD_FATAL(__FILE__."(".__LINE__."): ".CACHE_PROBLEMS_DETECTED);
+ addFatalMessage(__FILE__."(".__LINE__."): ".CACHE_PROBLEMS_DETECTED);
}
}
@@ -141,7 +142,7 @@ class CacheSystem {
}
} else {
// Cannot create file
- ADD_FATAL(__FILE__."(".__LINE__."): ".CACHE_PROBLEMS_DETECTED);
+ addFatalMessage(__FILE__."(".__LINE__."): ".CACHE_PROBLEMS_DETECTED);
}
}
@@ -159,6 +160,7 @@ class CacheSystem {
// Remove pointer
$this->pointer = false;
+ //* DEBUG: */ print __METHOD__."(".__LINE__."): {$this->name} - FINALIZED!
\n";
} // END - if
}
@@ -203,32 +205,32 @@ class CacheSystem {
}
} else {
// Cache file not found or not readable
- ADD_FATAL(__FILE__."(".__LINE__."): ".CACHE_CANNOT_LOAD_1.$this->inc.CACHE_CANNOT_LOAD_2);
+ addFatalMessage(__FILE__."(".__LINE__."): ".CACHE_CANNOT_LOAD_1.$this->inc.CACHE_CANNOT_LOAD_2);
}
}
// 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);
+ addFatalMessage(__FILE__."(".__LINE__."): ".CACHE_CANNOT_UNLINK_1.$this->inc.CACHE_CANNOT_UNLINK_2);
}
- } else {
- // Does not exist!
- ADD_FATAL(__FILE__."(".__LINE__."): ".CACHE_PROBLEMS_DETECTED);
- }
+ } // END - if
}
// Unused method:
@@ -244,7 +246,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();
@@ -257,7 +259,7 @@ class CacheSystem {
}
} else {
// Cannot write to cache!
- ADD_FATAL(__FILE__."(".__LINE__."): ".CACHE_PROBLEMS_DETECTED);
+ addFatalMessage(__FILE__."(".__LINE__."): ".CACHE_PROBLEMS_DETECTED);
}
}
@@ -281,7 +283,7 @@ class CacheSystem {
} // END - foreach
} else {
// Cannot write array!
- ADD_FATAL(__FILE__."(".__LINE__."): ".CACHE_PROBLEMS_DETECTED);
+ addFatalMessage(__FILE__."(".__LINE__."): ".CACHE_PROBLEMS_DETECTED);
}
}
@@ -303,8 +305,8 @@ class CacheSystem {
if ($a == $search) {
// Update now...
$dummy[$a][$search_key] = $replace;
- }
- }
+ } // END - if
+ } // END - foreach
// Flush array to cache file
$this->init();
@@ -314,11 +316,11 @@ class CacheSystem {
// Close cache file
$this->finalize();
- }
- }
+ } // END - if
+ } // END - if
} else {
// Cannot write to cache!
- ADD_FATAL(__FILE__."(".__LINE__."): ".CACHE_PROBLEMS_DETECTED);
+ addFatalMessage(__FILE__."(".__LINE__."): ".CACHE_PROBLEMS_DETECTED);
}
}
@@ -330,9 +332,13 @@ 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);
+ addFatalMessage(__FILE__."(".__LINE__."): ".CACHE_PROBLEMS_DETECTED);
}
}
@@ -343,6 +349,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));
}
@@ -378,5 +392,54 @@ 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("admins_acls")) $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();
+}
+
//
?>