More fixes for cache, extension and filter sub-system
[mailer.git] / inc / libs / cache_functions.php
index 1004594d625bef8b02329b9315b7a37b0fb682e2..15adc4680619d683518bb041cddce11807b4e788 100644 (file)
@@ -47,6 +47,7 @@ class CacheSystem {
        var $data = "";
        var $version = "";
        var $name = "";
+       var $rebuilt = array();
 
        // Constructor
        function CacheSystem ($interval, $path, $tested) {
@@ -159,6 +160,7 @@ class CacheSystem {
 
                        // Remove pointer
                        $this->pointer = false;
+                       //* DEBUG: */ print __METHOD__."(<font color=\"#0000aa\">".__LINE__."</font>): {$this->name} - FINALIZED!<br />\n";
                } // END - if
        }
 
@@ -210,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__."(<font color=\"#0000aa\">".__LINE__."</font>): {$this->name} - DESTROYED!<br />\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__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_CANNOT_UNLINK_1.$this->inc.CACHE_CANNOT_UNLINK_2);
@@ -244,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();
@@ -303,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();
@@ -314,8 +319,8 @@ class CacheSystem {
 
                                        // Close cache file
                                        $this->finalize();
-                               }
-                       }
+                               } // END - if
+                       } // END - if
                } else {
                        // Cannot write to cache!
                        ADD_FATAL(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_PROBLEMS_DETECTED);
@@ -330,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__."(<font color=\"#0000aa\">".__LINE__."</font>): {$this->name} - {$ext_name}={$ext_ver}<br />\n";
                } else {
                        // Cannot create file
                        ADD_FATAL(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_PROBLEMS_DETECTED);
@@ -343,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__."(<font color=\"#0000aa\">".__LINE__."</font>): cache={$this->name},ext_name={$ext_name} - {$ext_ver}/{$this->version[$this->name][$ext_name]}<br />\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));
        }
@@ -385,9 +402,9 @@ function FILTER_CACHE_DESTROY_ON_EXT_CHANGE () {
 
        // Update cache
        if (EXT_IS_ACTIVE("cache")) {
-               if ($cacheInstance->loadCacheFile("config"))           $cacheInstance->destroyCacheFile();
-               if ($cacheInstance->loadCacheFile("extensions", true)) $cacheInstance->destroyCacheFile();
-               if ($cacheInstance->loadCacheFile("mod_reg"))          $cacheInstance->destroyCacheFile();
+               if ($cacheInstance->loadCacheFile("config"))     $cacheInstance->destroyCacheFile();
+               if ($cacheInstance->loadCacheFile("extensions")) $cacheInstance->destroyCacheFile();
+               if ($cacheInstance->loadCacheFile("mod_reg"))    $cacheInstance->destroyCacheFile();
        } // END - if
 }
 
@@ -397,7 +414,23 @@ function FILTER_CACHE_DESTROY_ON_ADMIN_CHANGE () {
 
        // Update cache
        if (EXT_IS_ACTIVE("cache")) {
-               if ($cacheInstance->loadCacheFile("admin")) $cacheInstance->destroyCacheFile();
+               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
 }