]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/cache_functions.php
Global variables rewritten
[mailer.git] / inc / libs / cache_functions.php
index 611073a72ae89cba3603f1129bd3f217afc0c64b..98d29819ab9801c8780f0a95756d55f43c974191 100644 (file)
@@ -47,6 +47,7 @@ class CacheSystem {
        var $data = "";
        var $version = "";
        var $name = "";
+       var $rebuilt = array();
 
        // Constructor
        function CacheSystem ($interval, $path, $tested) {
@@ -83,12 +84,12 @@ class CacheSystem {
        }
 
        // Checks validity of cache file and if content is given
-       function loadCacheFile ($file, $forceContent = false) {
+       function loadCacheFile ($cacheName, $forceContent = false) {
                // Remember cache file
-               $this->name = $file;
+               $this->name = $cacheName;
 
                // Construct FQFN (full qualified file name)
-               $this->inc = $this->path.$file.".cache";
+               $this->inc = $this->path . $cacheName . ".cache";
 
                // Check if file exists and if version matches
                $status = (FILE_READABLE($this->inc) && (is_writeable($this->inc)) && ($this->extensionVersionMatches("cache")));
@@ -111,25 +112,24 @@ class CacheSystem {
                        $this->storeExtensionVersion("cache");
                } else {
                        // Cannot create file
-                       ADD_FATAL(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_PROBLEMS_DETECTED);
+                       addFatalMessage(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_PROBLEMS_DETECTED);
                }
        }
 
        function addRow ($data) {
-               global $cacheArray;
-
+               // Is the pointe rvalid?
                if (is_resource($this->pointer)) {
                        // Write every array element to cache file
                        foreach ($data as $k => $v) {
                                // Write global cache array for immediate access
                                if ((substr($k, 0, 4) == "ext_") && (isset($data['ext_name'])) && (isset($data['ext_id']))) {
                                        if ($k != "ext_name") {
-                                               $cacheArray['extensions'][$k][$data['ext_name']] = $v;
+                                               $GLOBALS['cache_array']['extensions'][$k][$data['ext_name']] = $v;
                                        } else {
-                                               $cacheArray['extensions'][$k][$data['ext_id']] = $v;
+                                               $GLOBALS['cache_array']['extensions'][$k][$data['ext_id']] = $v;
                                        }
                                        if (($k == "ext_keep") && ($v == "Y")) {
-                                               $cacheArray['active_extensions'][$data['ext_name']] = $v;
+                                               $GLOBALS['cache_array']['active_extensions'][$data['ext_name']] = $v;
                                        } // END - if
                                } elseif (is_array($v)) {
                                        // Serialize and BASE64-encode the array
@@ -141,7 +141,7 @@ class CacheSystem {
                        }
                } else {
                        // Cannot create file
-                       ADD_FATAL(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_PROBLEMS_DETECTED);
+                       addFatalMessage(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_PROBLEMS_DETECTED);
                }
        }
 
@@ -159,10 +159,8 @@ class CacheSystem {
 
                        // Remove pointer
                        $this->pointer = false;
-               } else {
-                       // Cannot create file
-                       ADD_FATAL(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_PROBLEMS_DETECTED);
-               }
+                       //* DEBUG: */ print __METHOD__."(<font color=\"#0000aa\">".__LINE__."</font>): {$this->name} - FINALIZED!<br />\n";
+               } // END - if
        }
 
        function getArrayFromCache () {
@@ -179,7 +177,7 @@ class CacheSystem {
                        $cache_version = null;
 
                        // Load cache file
-                       require_once($this->inc);
+                       LOAD_INC_ONCE($this->inc);
 
                        // Is there an array?
                        if (is_array($data)) {
@@ -206,32 +204,32 @@ class CacheSystem {
                        }
                } else {
                        // Cache file not found or not readable
-                       ADD_FATAL(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_CANNOT_LOAD_1.$this->inc.CACHE_CANNOT_LOAD_2);
+                       addFatalMessage(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".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__."(<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);
+                               addFatalMessage(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_CANNOT_UNLINK_1.$this->inc.CACHE_CANNOT_UNLINK_2);
                        }
-               } else {
-                       // Does not exist!
-                       ADD_FATAL(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_PROBLEMS_DETECTED);
-               }
+               } // END - if
        }
 
        // Unused method:
@@ -247,7 +245,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();
@@ -260,7 +258,7 @@ class CacheSystem {
                        }
                } else {
                        // Cannot write to cache!
-                       ADD_FATAL(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_PROBLEMS_DETECTED);
+                       addFatalMessage(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_PROBLEMS_DETECTED);
                }
        }
 
@@ -284,7 +282,7 @@ class CacheSystem {
                        } // END - foreach
                } else {
                        // Cannot write array!
-                       ADD_FATAL(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_PROBLEMS_DETECTED);
+                       addFatalMessage(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_PROBLEMS_DETECTED);
                }
        }
 
@@ -306,8 +304,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,11 +315,11 @@ 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);
+                       addFatalMessage(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_PROBLEMS_DETECTED);
                }
        }
 
@@ -333,9 +331,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__."(<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);
+                       addFatalMessage(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_PROBLEMS_DETECTED);
                }
        }
 
@@ -346,6 +348,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));
        }
@@ -381,5 +391,48 @@ class CacheSystem {
                return $this->ret;
        }
 }
+
+// Destroy the cache on extension changes
+function FILTER_CACHE_DESTROY_ON_EXT_CHANGE ($data) {
+       // Remove cache
+       if (EXT_IS_ACTIVE("cache")) {
+               if ($GLOBALS['cache_instance']->loadCacheFile("config"))     $GLOBALS['cache_instance']->destroyCacheFile();
+               if ($GLOBALS['cache_instance']->loadCacheFile("extensions")) $GLOBALS['cache_instance']->destroyCacheFile();
+               if ($GLOBALS['cache_instance']->loadCacheFile("mod_reg"))    $GLOBALS['cache_instance']->destroyCacheFile();
+       } // END - if
+
+       // Return it
+       return $data;
+}
+
+// Destroy the cache on changing admin
+function FILTER_CACHE_DESTROY_ON_ADMIN_CHANGE () {
+       // Remove cache
+       if (EXT_IS_ACTIVE("cache")) {
+               if ($GLOBALS['cache_instance']->loadCacheFile("admins")) $GLOBALS['cache_instance']->destroyCacheFile();
+       } // END - if
+}
+
+// Destroy all cache files
+function FILTER_CACHE_DESTROY_ALL () {
+       // Remove cache
+       if (EXT_IS_ACTIVE("cache")) {
+               if ($GLOBALS['cache_instance']->loadCacheFile("admins"))      $GLOBALS['cache_instance']->destroyCacheFile();
+               if ($GLOBALS['cache_instance']->loadCacheFile("admins_acls")) $GLOBALS['cache_instance']->destroyCacheFile();
+               if ($GLOBALS['cache_instance']->loadCacheFile("config"))      $GLOBALS['cache_instance']->destroyCacheFile();
+               if ($GLOBALS['cache_instance']->loadCacheFile("extensions"))  $GLOBALS['cache_instance']->destroyCacheFile();
+               if ($GLOBALS['cache_instance']->loadCacheFile("mod_reg"))     $GLOBALS['cache_instance']->destroyCacheFile();
+               if ($GLOBALS['cache_instance']->loadCacheFile("refdepths"))   $GLOBALS['cache_instance']->destroyCacheFile();
+               if ($GLOBALS['cache_instance']->loadCacheFile("refsystem"))   $GLOBALS['cache_instance']->destroyCacheFile();
+               if ($GLOBALS['cache_instance']->loadCacheFile("themes"))      $GLOBALS['cache_instance']->destroyCacheFile();
+       } // END - if
+}
+
+// Filter for purging entire admin menu cache
+function FILTER_CACHE_PURGE_ADMIN_MENU () {
+       // Just call the function
+       CACHE_PURGE_ADMIN_MENU();
+}
+
 //
 ?>