]> git.mxchange.org Git - mailer.git/blobdiff - inc/classes/cachesystem.class.php
www is out-dated
[mailer.git] / inc / classes / cachesystem.class.php
index ed67f4a32789ad60ce93fc3491e8fd924a2b52d5..e4db35bfcd156f60fe1d02d2f4382e285b079ea9 100644 (file)
@@ -16,8 +16,8 @@
  * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
- * For more information visit: http://www.mxchange.org                  *
+ * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
+ * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
  * it under the terms of the GNU General Public License as published by *
@@ -42,35 +42,48 @@ if (!defined('__SECURITY')) {
 
 // Caching class
 class CacheSystem {
-       // Define variables
-       var $ret = 'init';
+       // Status code
+       var $statusCode = 'init';
+
+       // Full-qualified filename
        var $fqfn = '';
+
+       // Resource to cache file
        var $pointer = false;
+
+       // Data array from cache
        var $data = array();
+
+       // Version data from cache
        var $version = array();
+
+       // Cache name
        var $name = '';
        var $rebuilt = array();
+
+       // File extension
        var $extension = '.cache';
-       var $statusDone = 'done';
        var $status = array();
        var $readable = array();
+       var $fullPath = '';
 
        // Constructor
        function CacheSystem () {
-               // Failed is the default
-               $this->ret = 'failed';
+               // Construct full path
+               $this->fullPath = getPath() . getCachePath();
 
-               // Remeber path
+               // Failed is the default
+               $this->setStatusCode('failed');
 
                // Check if path exists
-               if (isDirectory(getCachePath())) {
+               if (isDirectory($this->fullPath)) {
                        // Is there a .htaccess file?
-                       if (isFileReadable(getCachePath() . '.htaccess')) {
+                       if (isFileReadable($this->fullPath . '.htaccess')) {
                                // All done!
-                               $this->ret = $this->statusDone;
+                               $this->setStatusCode('done');
                        } else {
                                // Stop! Set a .htaccess file first
-                               $this->ret = 'htaccess';
+                               $this->setStatusCode('htaccess');
                        }
                } // END - if
        }
@@ -81,7 +94,7 @@ class CacheSystem {
                $this->name = $cacheName;
 
                // Construct FQFN (full qualified file name)
-               $this->fqfn = getCachePath() . $cacheName . $this->extension;
+               $this->fqfn = $this->fullPath . $cacheName . $this->extension;
 
                // Check if file exists and if version matches
                if (!isset($this->status[$cacheName])) {
@@ -100,7 +113,7 @@ class CacheSystem {
        // Initializes the cache file
        function init () {
                // This will destory an existing cache file!
-               if ($this->ret == $this->statusDone) {
+               if ($this->getStatusCode() == 'done') {
                        // Reset read status
                        $this->resetCacheReadStatus();
 
@@ -112,7 +125,7 @@ class CacheSystem {
                        $this->writeLine('<?php');
                } else {
                        // Cannot create file
-                       addFatalMessage(__METHOD__, __LINE__, '(<font color="#0000aa">' . __LINE__ . '</font>): {--CACHE_PROBLEMS_DETECTED');
+                       debug_report_bug(__METHOD__, __LINE__, 'Problems with cache directory detected, getStatusCode()=' . $this->getStatusCode());
                }
        }
 
@@ -172,6 +185,9 @@ class CacheSystem {
                                        } else {
                                                $GLOBALS['cache_array']['admin'][$k][$data['admin_id']] = $v;
                                        }
+                               } elseif ($this->name == 'admin_acls') {
+                                       // Access control lines
+                                       $GLOBALS['cache_array']['admin_acls'][$k][$data['admin_id']][] = $v;
                                } elseif ($this->name == 'refdepths') {
                                        // Referal levels
                                        $GLOBALS['cache_array']['refdepths'][$k][$data['id']] = $v;
@@ -191,6 +207,12 @@ class CacheSystem {
                                } elseif ($this->name == 'imprint') {
                                        // Imprint
                                        $GLOBALS['cache_array']['imprint'][$k][$data['imprint_id']] = $v;
+                               } elseif ($this->name == 'points_data') {
+                                       // Table 'points_data'
+                                       $GLOBALS['cache_array']['points_data'][$k][$data['id']] = $v;
+                               } elseif ($this->name == 'earning') {
+                                       // Table 'earning'
+                                       $GLOBALS['cache_array']['earning'][$k][$data['earning_id']] = $v;
                                } elseif (is_array($v)) {
                                        // Serialize and BASE64-encode the array
                                        $v = base64_encode(serialize($v));
@@ -201,7 +223,7 @@ class CacheSystem {
                                        // Remove cache
                                        $this->removeCacheFile(true);
 
-                                       // Unsupported cache found!
+                                       // Unsupported/unhandled cache detected
                                        debug_report_bug(__METHOD__, __LINE__, 'Unsupported cache ' . $this->name . ' detected.');
                                }
 
@@ -210,7 +232,7 @@ class CacheSystem {
                        } // END - foreach
                } else {
                        // Cannot create file
-                       addFatalMessage(__METHOD__, __LINE__, '(<font color="#0000aa">' . __LINE__ . '</font>): {--CACHE_PROBLEMS_DETECTED');
+                       debug_report_bug(__METHOD__, __LINE__, 'Problem with cache detected, no resource! pointer[]=' . gettype($this->pointer));
                }
        }
 
@@ -235,7 +257,7 @@ class CacheSystem {
                        // Remove pointer and status
                        unset($this->status[$this->name]);
                        $this->pointer = false;
-                       //* DEBUG: */ debugOutput(__METHOD__ . '(<font color="#0000aa">' . __LINE__.'</font>): '.$this->name.' - FINALIZED!');
+                       //* DEBUG: */ logDebugMessage(__METHOD__, __LINE__, 'name=' . $this->name . ' - FINALIZED!');
                } // END - if
        }
 
@@ -274,8 +296,7 @@ class CacheSystem {
                        } // END - if
                } else {
                        // Cache file not found or not readable
-                       debug_report_bug(__METHOD__, __LINE__, $this->name);
-                       addFatalMessage(__METHOD__, __LINE__, '(<font color="#0000aa">' . __LINE__ . '</font>): ' . getMaskedMessage('CACHE_CANNOT_LOAD', $this->fqfn));
+                       debug_report_bug(__METHOD__, __LINE__, '{%message,CACHE_CANNOT_LOAD=' . $this->name . '%}');
 
                        // Try to remove it
                        $this->removeCacheFile();
@@ -317,6 +338,7 @@ class CacheSystem {
                        } // END - if
 
                        // Remove cache file from system
+                       //* DEBUG: */ debug_report_bug(__METHOD__, __LINE__, 'About to remove ' . basename($this->fqfn) . '!');
                        removeFile($this->fqfn);
 
                        // Reset read status
@@ -330,14 +352,14 @@ class CacheSystem {
                                $this->rebuilt[$this->name] = true;
                        } else {
                                // Not removed!
-                               addFatalMessage(__METHOD__, __LINE__, '(<font color="#0000aa">' . __LINE__ . '</font>): ' . getMaskedMessage('CACHE_CANNOT_UNLINK', $this->fqfn));
+                               debug_report_bug(__METHOD__, __LINE__, '{%message,CACHE_CANNOT_UNLINK=' . $this->name . '%}');
                        }
                } // END - if
        }
 
        // Unused method:
        function removeEntry ($search, $data, $array) {
-               if ($this->status[$this->name] == $this->statusDone) {
+               if ($this->status[$this->name] == 'done') {
                        // Load cache into dummy array
                        $dummy = $this->getArrayFromCache();
 
@@ -358,10 +380,10 @@ class CacheSystem {
 
                                // Close cache file
                                $this->finalize();
-                       }
+                       } // END - if
                } else {
                        // Cannot write to cache!
-                       addFatalMessage(__METHOD__, __LINE__, '(<font color="#0000aa">' . __LINE__ . '</font>): {--CACHE_PROBLEMS_DETECTED');
+                       debug_report_bug(__METHOD__, __LINE__, 'Problem with cache detected: Unexpected status ' . $this->status[$this->name]);
                }
        }
 
@@ -371,10 +393,10 @@ class CacheSystem {
                                if (is_array($v)) {
                                        // Multi line(s) found
                                        $LINE = '';
-                                       foreach($v as $k2 => $v2) {
+                                       foreach ($v as $k2 => $v2) {
                                                // Put every array element in a row...
                                                $LINE .= $this->rewriteEntry($k, $v2);
-                                       }
+                                       } // END - foreach
                                } else {
                                        // Single line found
                                        $LINE = $this->rewriteEntry($k, $v);
@@ -385,13 +407,13 @@ class CacheSystem {
                        } // END - foreach
                } else {
                        // Cannot write array!
-                       addFatalMessage(__METHOD__, __LINE__, '(<font color="#0000aa">' . __LINE__ . '</font>): {--CACHE_PROBLEMS_DETECTED');
+                       debug_report_bug(__METHOD__, __LINE__, 'Problem with cache detected: pointer is not resource! pointer[]=' . gettype($this->pointer));
                }
        }
 
        // Unused method
        function replaceEntry ($search, $replace, $search_key, $array) {
-               if ($this->status[$this->name] == $this->statusDone) {
+               if ($this->status[$this->name] == 'done') {
                        // Load cache into dummy array
                        $dummy = $this->getArrayFromCache();
 
@@ -422,7 +444,7 @@ class CacheSystem {
                        } // END - if
                } else {
                        // Cannot write to cache!
-                       addFatalMessage(__METHOD__, __LINE__, '(<font color="#0000aa">' . __LINE__ . '</font>): {--CACHE_PROBLEMS_DETECTED');
+                       debug_report_bug(__METHOD__, __LINE__, 'Problem with cache detected: Unexpected status ' . $this->status[$this->name]);
                }
        }
 
@@ -441,10 +463,10 @@ class CacheSystem {
                                // Write cache line to file
                                $this->writeLine($this->rewriteEntry($ext_name, $ext_ver, 'version', true));
                        } // END - if
-                       //* DEBUG: */ debugOutput(__METHOD__ . '(<font color="#0000aa">' . __LINE__ . '</font>): '.$this->name.' - '.$ext_name.'='.$ext_ver);
+                       //* DEBUG: */ logDebugMessage(__METHOD__, __LINE__, 'name=' . $this->name . ',ext_name=' . $ext_name . ',ext_ver=' . $ext_ver);
                } else {
                        // Cannot create file
-                       addFatalMessage(__METHOD__, __LINE__, '(<font color="#0000aa">' . __LINE__ . '</font>): {--CACHE_PROBLEMS_DETECTED');
+                       debug_report_bug(__METHOD__, __LINE__, 'Problem with cache detected: pointer is not resource! pointer[]=' . gettype($this->pointer));
                }
        }
 
@@ -465,7 +487,7 @@ class CacheSystem {
                                        // Does it match?
                                        $GLOBALS[__METHOD__][$ext_name] = ((isset($this->version[$this->name][$ext_name])) && ($this->version[$this->name][$ext_name] == $ext_ver));
                                } elseif ($this->isCacheReadable()) {
-                                       // No cache version found!
+                                       // No cache version found
                                        logDebugMessage(__METHOD__, __LINE__, 'Cache ' . $this->name . ' has missing version entry for extension ' . $ext_name . '! Purging cache...');
        
                                        // Remove the cache file
@@ -504,7 +526,7 @@ class CacheSystem {
                        $line = '$this->' . $prefix . "['" . $this->name . "']['" . $key . "']" . $extender . " = '" . escapeQuotes($value) . "';";
                } elseif (is_null($value)) {
                        // Null
-                       $line = '$this->' . $prefix . "['" . $this->name . "']['" . $key . "']" . $extender . ' = null;';
+                       $line = '$this->' . $prefix . "['" . $this->name . "']['" . $key . "']" . $extender . ' = NULL;';
                } elseif (is_bool($value)) {
                        // Boolean value
                        if ($value === true) {
@@ -526,9 +548,14 @@ class CacheSystem {
                return $line;
        }
 
-       // Getter for cache status
-       function getStatus () {
-               return $this->ret;
+       // Getter for cache status code
+       function getStatusCode () {
+               return $this->statusCode;
+       }
+
+       // Setter for cache status code
+       function setStatusCode ($status) {
+               $this->statusCode = $status;
        }
 
        // Checks wether the current cache file is readable