From: Gunnar Wrobel Date: Tue, 27 Apr 2010 05:23:39 +0000 (+0200) Subject: Start injecting the cache dependency into Kolab_Storage. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=769b289d45be1eca345ea984bfe33c56a074d523;p=horde.git Start injecting the cache dependency into Kolab_Storage. --- diff --git a/framework/Core/lib/Horde/Core/Factory/KolabStorage.php b/framework/Core/lib/Horde/Core/Factory/KolabStorage.php index e7bb3bc84..0babf6ab8 100644 --- a/framework/Core/lib/Horde/Core/Factory/KolabStorage.php +++ b/framework/Core/lib/Horde/Core/Factory/KolabStorage.php @@ -113,6 +113,7 @@ class Horde_Core_Factory_KolabStorage return new Horde_Kolab_Storage( $master, + $this->_injector->getInstance('Horde_Cache'), $params ); } diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage.php index ca4f1af48..e81a5e2df 100644 --- a/framework/Kolab_Storage/lib/Horde/Kolab/Storage.php +++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage.php @@ -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) diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache.php index a6fd4b628..89dd80e1e 100644 --- a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache.php +++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache.php @@ -13,11 +13,6 @@ */ /** - * 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; } /** diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Data.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Data.php index 104b83b44..cdc5d27d7 100644 --- a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Data.php +++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Data.php @@ -14,11 +14,6 @@ */ /** - * 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) { } } diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Base.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Base.php index 0fdae63cf..bbaeeca40 100644 --- a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Base.php +++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Base.php @@ -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.