Start injecting the cache dependency into Kolab_Storage.
authorGunnar Wrobel <p@rdus.de>
Tue, 27 Apr 2010 05:23:39 +0000 (07:23 +0200)
committerGunnar Wrobel <wrobel@temple.(none)>
Tue, 27 Apr 2010 05:34:50 +0000 (07:34 +0200)
framework/Core/lib/Horde/Core/Factory/KolabStorage.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Data.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Base.php

index e7bb3bc..0babf6a 100644 (file)
@@ -113,6 +113,7 @@ class Horde_Core_Factory_KolabStorage
 
         return new Horde_Kolab_Storage(
             $master,
+            $this->_injector->getInstance('Horde_Cache'),
             $params
         );
     }
index ca4f1af..e81a5e2 100644 (file)
@@ -116,9 +116,11 @@ class Horde_Kolab_Storage
      */
     public function __construct(
         Horde_Kolab_Storage_Driver $master,
+        Horde_Cache $cache,
         $params = array()
     ) {
         $this->_master = $master;
+        $this->_cache  = new Horde_Kolab_Storage_Cache($cache);
 
         $this->_params = $params;
 
@@ -221,6 +223,16 @@ class Horde_Kolab_Storage
     }
 
     /**
+     * Return the data cache associated with this storage instance.
+     *
+     * @return Horde_Kolab_Storage_Cache The cache object
+     */
+    public function getDataCache()
+    {
+        return $this->_cache;
+    }
+
+    /**
      * Return the connection driver and the folder name for the given key.
      *
      * @param string $key The key specifying a connection (may be a folder name)
index a6fd4b6..89dd80e 100644 (file)
  */
 
 /**
- * The Autoloader allows us to omit "require/include" statements.
- */
-require_once 'Horde/Autoloader.php';
-
-/**
  * The Kolab_Cache class provides a cache for Kolab groupware objects.
  *
  * The Horde_Kolab_Storage_Cache singleton instance provides caching for all
@@ -43,13 +38,6 @@ require_once 'Horde/Autoloader.php';
 class Horde_Kolab_Storage_Cache
 {
     /**
-     * Singleton instance.
-     *
-     * @var array
-     */
-    static protected $instance;
-
-    /**
      * The version of the cache we loaded.
      *
      * @var int
@@ -134,42 +122,11 @@ class Horde_Kolab_Storage_Cache
     /**
      * Constructor.
      *
-     * @todo Improve the cache setup and allow different cache types.
-     *
-     * @throws Horde_Exception
-     */
-    public function __construct()
-    {
-        if (!isset($GLOBALS['conf']['kolab']['storage']['cache']['data']['driver'])) {
-            $driver = 'file';
-            $params = array('prefix' => 'kolab_cache', 'dir' => Horde::getTempDir());
-        } else {
-            $driver = $GLOBALS['conf']['kolab']['storage']['cache']['data']['driver'];
-            if (!isset($GLOBALS['conf']['kolab']['storage']['cache']['data']['params'])) {
-
-                $params = array();
-            } else {
-                $params = $GLOBALS['conf']['kolab']['storage']['cache']['data']['params'];
-            }
-        }
-        $this->horde_cache = Horde_Cache::factory($driver, $params);
-    }
-
-    /**
-     * Attempts to return a reference to a concrete Horde_Kolab_Storage_Cache
-     * instance.  It will only create a new instance if no
-     * Horde_Kolab_Storage_Cache instance currently exists.
-     *
-     * @return Horde_Kolab_Storage_Cache The concrete Horde_Kolab_Storage_Cache
-     *                                   reference, or false on error.
+     * @param Horde_Cache $cache The global cache for temporary data storage.
      */
-    static public function singleton()
+    public function __construct($cache)
     {
-        if (!isset(self::$instance)) {
-            self::$instance = new self();
-        }
-
-        return self::$instance;
+        $this->horde_cache = $cache;
     }
 
     /**
index 104b83b..cdc5d27 100644 (file)
  */
 
 /**
- * The Autoloader allows us to omit "require/include" statements.
- */
-require_once 'Horde/Autoloader.php';
-
-/**
  * The Kolab_Data class represents a data type in a Kolab storage
  * folder on the Kolab server.
  *
@@ -116,17 +111,6 @@ class Horde_Kolab_Storage_Data
         } else {
             $this->_type_key = '';
         }
-        $this->__wakeup();
-    }
-
-    /**
-     * Initializes the object.
-     *
-     * @return NULL
-     */
-    public function __wakeup()
-    {
-        $this->_cache = &Horde_Kolab_Storage_Cache::singleton();
     }
 
     /**
@@ -145,17 +129,29 @@ class Horde_Kolab_Storage_Data
     /**
      * Set the folder handler for this data instance.
      *
-     * @param Kolab_Folder &$folder The handler for the folder.
+     * @param Kolab_Folder $folder The handler for the folder.
      *
      * @return NULL
      */
-    public function setFolder(&$folder)
+    public function setFolder($folder)
     {
-        $this->_folder    = &$folder;
+        $this->_folder    = $folder;
         $this->_cache_key = $this->getCacheKey();
     }
 
     /**
+     * Set the folder handler for this data instance.
+     *
+     * @param Kolab_Folder &$folder The handler for the folder.
+     *
+     * @return NULL
+     */
+    public function setCache($cache)
+    {
+        $this->_cache = $cache;
+    }
+
+    /**
      * Expire the cache.
      *
      * @return NULL
@@ -475,10 +471,10 @@ class Horde_Kolab_Storage_Data
 
         /* Log the action on this item in the history log. */
         try {
-            $GLOBALS['injector']->getInstance('Horde_History')
-                ->log($app . ':' . $this->_folder->getShareId() . ':' . $object_uid,
-                      array('action' => $action, 'ts' => $mod_ts),
-                      true);
+            /* $GLOBALS['injector']->getInstance('Horde_History') */
+            /*     ->log($app . ':' . $this->_folder->getShareId() . ':' . $object_uid, */
+            /*           array('action' => $action, 'ts' => $mod_ts), */
+            /*           true); */
         } catch (Horde_Exception $e) {
         }
     }
index 0fdae63..bbaeeca 100644 (file)
@@ -687,7 +687,7 @@ implements Horde_Kolab_Storage_Folder
      *
      * @return Horde_Kolab_Storage_Data The data handler.
      */
-    function &getData($object_type = null, $data_version = 1)
+    public function getData($object_type = null, $data_version = 1)
     {
         if (empty($object_type)) {
             $object_type = $this->getType();
@@ -712,6 +712,7 @@ implements Horde_Kolab_Storage_Folder
             }
             $data = new Horde_Kolab_Storage_Data($type, $object_type, $data_version);
             $data->setFolder($this);
+            $data->setCache($this->_storage->getDataCache());
             $data->synchronize();
             $this->_data[$key] = &$data;
         }
@@ -937,11 +938,9 @@ implements Horde_Kolab_Storage_Folder
             }
         }
 
-        $session = &Horde_Kolab_Session_Singleton::singleton();
-
         // Update email headers
-        $new_headers->addHeader('From', $session->user_mail);
-        $new_headers->addHeader('To', $session->user_mail);
+        $new_headers->addHeader('From', $this->_driver->getAuth());
+        $new_headers->addHeader('To', $this->_driver->getAuth());
         $new_headers->addHeader('Date', date('r'));
         $new_headers->addHeader('X-Kolab-Type', $handlers['XML']->getMimeType());
         $new_headers->addHeader('Subject', $object['uid']);
@@ -1124,7 +1123,7 @@ implements Horde_Kolab_Storage_Folder
     }
 
     /**
-     * Get annotation values on IMAP server that do not support
+     * Get annotation values on IMAP servers that do not support
      * METADATA.
      *
      * @return array|PEAR_Error  The anotations of this folder.