remove unused cache system
authorStricted <info@stricted.de>
Sat, 21 Feb 2015 07:04:35 +0000 (08:04 +0100)
committerStricted <info@stricted.de>
Sat, 21 Feb 2015 07:04:35 +0000 (08:04 +0100)
cache/.gitignore [deleted file]
lib/page/ApiPage.class.php
lib/system/SingletonFactory.class.php [deleted file]
lib/system/cache/CacheHandler.class.php [deleted file]
lib/system/cache/builder/AbstractCacheBuilder.class.php [deleted file]
lib/system/cache/builder/DNSApiCacheBuilder.class.php [deleted file]
lib/system/cache/builder/ICacheBuilder.class.php [deleted file]
lib/system/cache/source/DiskCacheSource.class.php [deleted file]
lib/system/cache/source/ICacheSource.class.php [deleted file]

diff --git a/cache/.gitignore b/cache/.gitignore
deleted file mode 100644 (file)
index 66ca35b..0000000
+++ /dev/null
@@ -1 +0,0 @@
-*.php
\ No newline at end of file
index d52058d720b1208a057bf482ad884546008d71f3..61fc7625bca675ab36d83692936aa6f5aeda07ac 100644 (file)
@@ -1,6 +1,5 @@
 <?php
 namespace dns\page;
-use dns\system\cache\builder\DNSApiCacheBuilder;
 use dns\system\DNS;
 
 /**
@@ -12,6 +11,7 @@ class ApiPage extends AbstractPage {
        const AVAILABLE_DURING_OFFLINE_MODE = true;
        
        public function prepare() {
+               // todo: user/server seletion
                $key = "";
                if (isset($_REQUEST['key'])) {
                        $key = $_REQUEST['key'];
@@ -23,7 +23,34 @@ class ApiPage extends AbstractPage {
                        exit;
                }
                else {
-                       $data = DNSApiCacheBuilder::getInstance()->getData();
+                       $data = array();
+                       
+                       $sql = "SELECT * FROM dns_soa where active = ?";
+                       $statement = DNS::getDB()->query($sql, array(1));
+                       
+                       while ($zone = DNS::getDB()->fetch_array($statement)) {
+                               $data[$zone['origin']] = array();
+                               $data[$zone['origin']]['soa'] = $zone;
+                               $data[$zone['origin']]['rr'] = array();
+                               $data[$zone['origin']]['sec'] = array();
+                               
+                               /* resource records */
+                               $sql2 = "SELECT * FROM dns_rr where zone = ? and active = ?";
+                               $statement2 = DNS::getDB()->query($sql2, array($zone['id'], 1));
+                               while ($rr = DNS::getDB()->fetch_array($statement2)) {
+                                       $data[$zone['origin']]['rr'][] = $rr;
+                               }
+                               
+                               if (ENABLE_DNSSEC) {
+                                       /* dnssec keys */
+                                       $sql3 = "SELECT * FROM dns_sec where zone = ? and active = ?";
+                                       $statement3 = DNS::getDB()->query($sql3, array($zone['id'], 1));
+                                       while ($sec = DNS::getDB()->fetch_array($statement3)) {
+                                               $data[$zone['origin']]['sec'][] = $sec;
+                                       }
+                               }
+                       }
+
                        header('Content-Type: application/json');
                        echo json_encode($data, JSON_PRETTY_PRINT);
                        exit;
diff --git a/lib/system/SingletonFactory.class.php b/lib/system/SingletonFactory.class.php
deleted file mode 100644 (file)
index c5fee78..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-<?php
-namespace dns\system;
-
-/**
- * Basis class for singleton classes.
- * 
- * @author     Alexander Ebert
- * @copyright  2001-2014 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package    com.woltlab.wcf
- * @subpackage system
- * @category   Community Framework
- */
-abstract class SingletonFactory {
-       /**
-        * list of singletons
-        * @var array<SingletonFactory>
-        */
-       protected static $__singletonObjects = array();
-       
-       /**
-        * Singletons do not support a public constructor. Override init() if
-        * your class needs to initialize components on creation.
-        */
-       protected final function __construct() {
-               $this->init();
-       }
-       
-       /**
-        * Called within __construct(), override if neccessary.
-        */
-       protected function init() { }
-       
-       /**
-        * Object cloning is disallowed.
-        */
-       protected final function __clone() { }
-       
-       /**
-        * Object serializing is disallowed.
-        */
-       public final function __sleep() {
-               throw new \Exception('Serializing of Singletons is not allowed');
-       }
-       
-       /**
-        * Returns an unique instance of current child class.
-        * 
-        * @return      \dns\system\SingletonFactory
-        */
-       public static final function getInstance() {
-               $className = get_called_class();
-               if (!array_key_exists($className, self::$__singletonObjects)) {
-                       self::$__singletonObjects[$className] = null;
-                       self::$__singletonObjects[$className] = new $className();
-               }
-               else if (self::$__singletonObjects[$className] === null) {
-                       throw new \Exception("Infinite loop detected while trying to retrieve object for '".$className."'");
-               }
-               
-               return self::$__singletonObjects[$className];
-       }
-       
-       /**
-        * Returns whether this singleton is already initialized.
-        * 
-        * @return      boolean
-        */
-       public static final function isInitialized() {
-               $className = get_called_class();
-               
-               return isset(self::$__singletonObjects[$className]);
-       }
-}
diff --git a/lib/system/cache/CacheHandler.class.php b/lib/system/cache/CacheHandler.class.php
deleted file mode 100644 (file)
index 88b861a..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-<?php
-namespace dns\system\cache;
-use dns\system\cache\builder\ICacheBuilder;
-use dns\system\cache\source\DiskCacheSource;
-use dns\system\SingletonFactory;
-
-define('CACHE_SOURCE_TYPE', 'disk');
-
-/**
- * Manages transparent cache access.
- * 
- * @author     Alexander Ebert, Marcel Werk
- * @copyright  2001-2014 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package    com.woltlab.wcf
- * @subpackage system.cache
- * @category   Community Framework
- */
-class CacheHandler extends SingletonFactory {
-       /**
-        * cache source object
-        * @var \dns\system\cache\source\ICacheSource
-        */
-       protected $cacheSource = null;
-       
-       /**
-        * Creates a new CacheHandler object.
-        */
-       protected function init() {
-               // init cache source object
-               try {
-                       $className = 'dns\system\cache\source\\'.ucfirst(CACHE_SOURCE_TYPE).'CacheSource';
-                       if (class_exists($className)) {
-                               $this->cacheSource = new $className();
-                       }
-                       else {
-                               // fallback to disk cache
-                               $this->cacheSource = new DiskCacheSource();
-                       }
-               }
-               catch (\Exception $e) {
-                       if (CACHE_SOURCE_TYPE != 'disk') {
-                               // fallback to disk cache
-                               $this->cacheSource = new DiskCacheSource();
-                       }
-                       else {
-                               throw $e;
-                       }
-               }
-       }
-       
-       /**
-        * Flush cache for given resource.
-        * 
-        * @param       \dns\system\cache\builder\ICacheBuilder         $cacheBuilder
-        * @param       array                                           $parameters
-        */
-       public function flush(ICacheBuilder $cacheBuilder, array $parameters) {
-               $this->getCacheSource()->flush($this->getCacheName($cacheBuilder, $parameters), empty($parameters));
-       }
-       
-       /**
-        * Flushes the entire cache.
-        */
-       public function flushAll() {
-               $this->getCacheSource()->flushAll();
-       }
-       
-       /**
-        * Returns cached value for given resource, false if no cache exists.
-        * 
-        * @param       \dns\system\cache\builder\ICacheBuilder         $cacheBuilder
-        * @param       array                                           $parameters
-        * @return      mixed
-        */
-       public function get(ICacheBuilder $cacheBuilder, array $parameters) {
-               return $this->getCacheSource()->get($this->getCacheName($cacheBuilder, $parameters), $cacheBuilder->getMaxLifetime());
-       }
-       
-       /**
-        * Caches a value for given resource,
-        * 
-        * @param       \dns\system\cache\builder\ICacheBuilder         $cacheBuilder
-        * @param       array                                           $parameters
-        * @param       array                                           $data
-        */
-       public function set(ICacheBuilder $cacheBuilder, array $parameters, array $data) {
-               $this->getCacheSource()->set($this->getCacheName($cacheBuilder, $parameters), $data, $cacheBuilder->getMaxLifetime());
-       }
-       
-       /**
-        * Returns cache index hash.
-        * 
-        * @param       array           $parameters
-        * @return      string
-        */
-       public function getCacheIndex(array $parameters) {
-               return sha1(serialize($this->orderParameters($parameters)));
-       }
-       
-       /**
-        * Builds cache name.
-        * 
-        * @param       \dns\system\cache\builder\ICacheBuilder         $cacheBuilder
-        * @param       array                                           $parameters
-        * @return      string
-        */
-       protected function getCacheName(ICacheBuilder $cacheBuilder, array $parameters = array()) {
-               $className = explode('\\', get_class($cacheBuilder));
-               $cacheName = str_replace('CacheBuilder', '', array_pop($className));
-               if (!empty($parameters)) {
-                       $cacheName .= '-' . $this->getCacheIndex($parameters);
-               }
-               
-               return ucfirst($cacheName);
-       }
-       
-       /**
-        * Returns the cache source object.
-        * 
-        * @return      \dns\system\cache\source\ICacheSource
-        */
-       public function getCacheSource() {
-               return $this->cacheSource;
-       }
-       
-       /**
-        * Unifys parameter order, numeric indizes will be discarded.
-        * 
-        * @param       array           $parameters
-        * @return      array
-        */
-       protected function orderParameters($parameters) {
-               if (!empty($parameters)) {
-                       array_multisort($parameters);
-               }
-               
-               return $parameters;
-       }
-}
diff --git a/lib/system/cache/builder/AbstractCacheBuilder.class.php b/lib/system/cache/builder/AbstractCacheBuilder.class.php
deleted file mode 100644 (file)
index d2ffe24..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-<?php
-namespace dns\system\cache\builder;
-use dns\system\cache\CacheHandler;
-use dns\system\SingletonFactory;
-
-/**
- * Default implementation for cache builders.
- * 
- * @author     Alexander Ebert
- * @copyright  2001-2014 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package    com.woltlab.wcf
- * @subpackage system.cache.builder
- * @category   Community Framework
- */
-abstract class AbstractCacheBuilder extends SingletonFactory implements ICacheBuilder {
-       /**
-        * list of cache resources by index
-        * @var array<array>
-        */
-       protected $cache = array();
-       
-       /**
-        * maximum cache lifetime in seconds, '0' equals infinite
-        * @var integer
-        */
-       protected $maxLifetime = 0;
-       
-       /**
-        * @see \dns\system\cache\builder\ICacheBuilder::getData()
-        */
-       public function getData(array $parameters = array(), $arrayIndex = '') {
-               $index = CacheHandler::getInstance()->getCacheIndex($parameters);
-               
-               if (!isset($this->cache[$index])) {
-                       // fetch cache or rebuild if missing
-                       $this->cache[$index] = CacheHandler::getInstance()->get($this, $parameters);
-                       if ($this->cache[$index] === null) {
-                               $this->cache[$index] = $this->rebuild($parameters);
-                               
-                               // update cache
-                               CacheHandler::getInstance()->set($this, $parameters, $this->cache[$index]);
-                       }
-               }
-               
-               if (!empty($arrayIndex)) {
-                       if (!isset($this->cache[$index][$arrayIndex])) {
-                               throw new \Exception("array index '".$arrayIndex."' does not exist in cache resource");
-                       }
-                       
-                       return $this->cache[$index][$arrayIndex];
-               }
-               
-               return $this->cache[$index];
-       }
-       
-       /**
-        * @see \dns\system\cache\builder\ICacheBuilder::getMaxLifetime()
-        */
-       public function getMaxLifetime() {
-               return $this->maxLifetime;
-       }
-       
-       /**
-        * @see \dns\system\cache\builder\ICacheBuilder::reset()
-        */
-       public function reset(array $parameters = array()) {
-               CacheHandler::getInstance()->flush($this, $parameters);
-       }
-       
-       /**
-        * Rebuilds cache for current resource.
-        * 
-        * @param       array           $parameters
-        */
-       abstract protected function rebuild(array $parameters);
-}
diff --git a/lib/system/cache/builder/DNSApiCacheBuilder.class.php b/lib/system/cache/builder/DNSApiCacheBuilder.class.php
deleted file mode 100644 (file)
index 97d7346..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-<?php
-namespace dns\system\cache\builder;
-use dns\system\DNS;
-
-/**
- * @author      Jan Altensen (Stricted)
- * @copyright   2013-2015 Jan Altensen (Stricted)
- */
-class DNSApiCacheBuilder extends AbstractCacheBuilder {
-       /**
-        * @see \dns\system\cache\builder\AbstractCacheBuilder::$maxLifetime
-        */
-       protected $maxLifetime = 30;
-       
-       /**
-        * @see \dns\system\cache\builder\AbstractCacheBuilder::rebuild()
-        */
-       public function rebuild(array $parameters) {
-               $data = array();
-               
-               $sql = "SELECT * FROM dns_soa where active = ?";
-               $statement = DNS::getDB()->query($sql, array(1));
-               
-               while ($zone = DNS::getDB()->fetch_array($statement)) {
-                       $data[$zone['origin']] = array();
-                       $data[$zone['origin']]['soa'] = $zone;
-                       $data[$zone['origin']]['rr'] = array();
-                       $data[$zone['origin']]['sec'] = array();
-                       
-                       /* resource records */
-                       $sql2 = "SELECT * FROM dns_rr where zone = ? and active = ?";
-                       $statement2 = DNS::getDB()->query($sql2, array($zone['id'], 1));
-                       while ($rr = DNS::getDB()->fetch_array($statement2)) {
-                               $data[$zone['origin']]['rr'][] = $rr;
-                       }
-                       
-                       if (ENABLE_DNSSEC) {
-                               /* dnssec keys */
-                               $sql3 = "SELECT * FROM dns_sec where zone = ? and active = ?";
-                               $statement3 = DNS::getDB()->query($sql3, array($zone['id'], 1));
-                               while ($sec = DNS::getDB()->fetch_array($statement3)) {
-                                       $data[$zone['origin']]['sec'][] = $sec;
-                               }
-                       }
-               }
-               
-               return $data;
-       }
-}
diff --git a/lib/system/cache/builder/ICacheBuilder.class.php b/lib/system/cache/builder/ICacheBuilder.class.php
deleted file mode 100644 (file)
index 608e05b..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-<?php
-namespace dns\system\cache\builder;
-
-/**
- * A cache builder provides data for the cache handler that ought to be cached.
- * 
- * @author     Alexander Ebert
- * @copyright  2001-2014 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package    com.woltlab.wcf
- * @subpackage system.cache.builder
- * @category   Community Framework
- */
-interface ICacheBuilder {
-       /**
-        * Returns the data that ought to be cached.
-        * 
-        * @param       array           $parameters
-        * @param       string          $arrayIndex
-        * @return      array
-        */
-       public function getData(array $parameters = array(), $arrayIndex = '');
-       
-       /**
-        * Returns maximum lifetime for cache resource.
-        * 
-        * @return      integer
-        */
-       public function getMaxLifetime();
-       
-       /**
-        * Flushes cache. If no parameters are given, all caches starting with
-        * the same cache name will be flushed too.
-        * 
-        * @param       array           $parameters
-        */
-       public function reset(array $parameters = array());
-}
diff --git a/lib/system/cache/source/DiskCacheSource.class.php b/lib/system/cache/source/DiskCacheSource.class.php
deleted file mode 100644 (file)
index 162522f..0000000
+++ /dev/null
@@ -1,152 +0,0 @@
-<?php
-namespace dns\system\cache\source;
-
-/**
- * DiskCacheSource is an implementation of CacheSource that stores the cache as simple files in the file system.
- * 
- * @author     Alexander Ebert, Marcel Werk
- * @copyright  2001-2014 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package    com.woltlab.wcf
- * @subpackage system.cache.source
- * @category   Community Framework
- */
-class DiskCacheSource implements ICacheSource {
-       /**
-        * @see \dns\system\cache\source\ICacheSource::flush()
-        */
-       public function flush($cacheName, $useWildcard) {
-               if ($useWildcard) {
-                       $this->removeFiles('cache.'.$cacheName.'*.php');
-               }
-               else {
-                       $this->removeFiles('cache.'.$cacheName.'.php');
-               }
-       }
-       
-       /**
-        * @see \dns\system\cache\source\ICacheSource::flushAll()
-        */
-       public function flushAll() {
-               $this->removeFiles('cache.*.php');
-       }
-       
-       /**
-        * @see \dns\system\cache\source\ICacheSource::get()
-        */
-       public function get($cacheName, $maxLifetime) {
-               $filename = $this->getFilename($cacheName);
-               if ($this->needRebuild($filename, $maxLifetime)) {
-                       return null;
-               }
-               
-               // load cache
-               try {
-                       return $this->readCache($cacheName, $filename);
-               }
-               catch (\Exception $e) {
-                       return null;
-               }
-       }
-       
-       /**
-        * @see \dns\system\cache\source\ICacheSource::set()
-        */
-       public function set($cacheName, $value, $maxLifetime) {
-               $filename = $this->getFilename($cacheName);
-               $content = "<?php exit; /* cache: ".$cacheName." (generated at ".gmdate('r').") DO NOT EDIT THIS FILE */ ?>\n";
-               $content .= serialize($value);
-               
-               if (!file_exists($filename)) {
-                       @touch($filename);
-               }
-               
-               $handler = fOpen($filename, "a+");
-               fWrite($handler, $content);
-               fClose($handler);
-       }
-       
-       /**
-        * Returns cache filename.
-        * 
-        * @param       string          $cacheName
-        * @return      string
-        */
-       protected function getFilename($cacheName) {
-               return DNS_DIR.'/cache/cache.'.$cacheName.'.php';
-       }
-       
-       /**
-        * Removes files matching given pattern.
-        * 
-        * @param       string          $pattern
-        */
-       protected function removeFiles($pattern) {
-               $directory = DNS_DIR.'cache/';
-               
-               foreach (glob($directory.$pattern) as $filename) {
-                       @unlink($filename);
-               }
-       }
-       
-       /**
-        * Determines wheater the cache needs to be rebuild or not.
-        * 
-        * @param       string          $filename
-        * @param       integer         $maxLifetime
-        * @return      boolean
-        */
-       protected function needRebuild($filename, $maxLifetime) {
-               // cache does not exist
-               if (!file_exists($filename)) {
-                       return true;
-               }
-               
-               // cache is empty
-               if (!@filesize($filename)) {
-                       return true;
-               }
-               
-               // cache resource was marked as obsolete
-               if (($mtime = filemtime($filename)) <= 1) {
-                       return true;
-               }
-               
-               // maxlifetime expired
-               if ($maxLifetime > 0 && (time() - $mtime) > $maxLifetime) {
-                       return true;
-               }
-               
-               // do not rebuild cache
-               return false;
-       }
-       
-       /**
-        * Loads the file of a cached resource.
-        * 
-        * @param       string          $cacheName
-        * @param       string          $filename
-        * @return      mixed
-        */
-       protected function readCache($cacheName, $filename) {
-               // get file contents
-               $contents = file_get_contents($filename);
-               
-               // find first newline
-               $position = strpos($contents, "\n");
-               if ($position === false) {
-                       throw new \Exception("Unable to load cache resource '".$cacheName."'");
-               }
-               
-               // cut contents
-               $contents = substr($contents, $position + 1);
-               
-               // unserialize
-               $value = @unserialize($contents);
-               if ($value === false) {
-                       throw new \Exception("Unable to load cache resource '".$cacheName."'");
-               }
-               
-               return $value;
-       }
-}
diff --git a/lib/system/cache/source/ICacheSource.class.php b/lib/system/cache/source/ICacheSource.class.php
deleted file mode 100644 (file)
index 95237fb..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-<?php
-namespace dns\system\cache\source;
-
-/**
- * Any cache sources should implement this interface.
- * 
- * @author     Alexander Ebert
- * @copyright  2001-2014 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package    com.woltlab.wcf
- * @subpackage system.cache.source
- * @category   Community Framework
- */
-interface ICacheSource {
-       /**
-        * Flushes a specific cache, optionally removing caches which share the same name.
-        * 
-        * @param       string          $cacheName
-        * @param       boolean         $useWildcard
-        */
-       public function flush($cacheName, $useWildcard);
-       
-       /**
-        * Clears the cache completely.
-        */
-       public function flushAll();
-       
-       /**
-        * Returns a cached variable.
-        * 
-        * @param       string          $cacheName
-        * @param       integer         $maxLifetime
-        * @return      mixed
-        */
-       public function get($cacheName, $maxLifetime);
-       
-       /**
-        * Stores a variable in the cache.
-        * 
-        * @param       string          $cacheName
-        * @param       mixed           $value
-        * @param       integer         $maxLifetime
-        */
-       public function set($cacheName, $value, $maxLifetime);
-}