/** * Return the Horde_Kolab_Storage:: instance. * * @return Horde_Kolab_Storage The storage handler. */ public function create() { $configuration = $this->_injector->getInstance('Horde_Kolab_Storage_Configuration'); $params = array('driver' => 'horde', 'params' => array('host' => $configuration['server'], 'username' => $GLOBALS['registry']->getAuth(), 'password' => $GLOBALS['registry']->getAuthCredential('password'), 'port' => $configuration['port'], 'secure' => $configuration['secure']), 'queries' => array('list' => array(Horde_Kolab_Storage_List_Tools::QUERY_BASE => array('cache' => true), Horde_Kolab_Storage_List_Tools::QUERY_ACL => array('cache' => true), Horde_Kolab_Storage_List_Tools::QUERY_SHARE => array('cache' => true))), 'queryset' => array('data' => array('queryset' => 'horde')), 'logger' => $this->_injector->getInstance('Horde_Log_Logger'), 'log' => array('debug'), 'cache' => $this->_injector->getInstance('Horde_Cache')); $factory = new Horde_Kolab_Storage_Factory($params); return $factory->create(); }
/** * Create a SQL next generate share setup. * * @param array $params Additional options. * <pre> * 'user' - (string) The current user. * 'imapuser' - (string) The short IMAP ID of the user. * </pre> * * @return Horde_Share_Sqlng The share setup. */ public function create($params) { if (!class_exists('Horde_Kolab_Storage_Factory')) { throw new Horde_Test_Exception('The "Horde_Kolab_Storage_Factory" class is unavailable!'); } $kolab_factory = new Horde_Kolab_Storage_Factory(array('driver' => 'mock', 'queryset' => array('list' => array('queryset' => 'horde')), 'params' => array('username' => $params['user'], 'host' => 'localhost', 'port' => 143, 'data' => array('user/' . $params['imapuser'] => array('permissions' => array('anyone' => 'alrid')))), 'logger' => new Horde_Support_Stub())); return $kolab_factory->create(); }
public static function setUpBeforeClass() { if (!class_exists('Horde_Kolab_Storage_Driver_Mock_Data')) { return; } self::$_data = new Horde_Kolab_Storage_Driver_Mock_Data(array('' => array('permissions' => array('anyone' => 'alrid')), 'user/john' => array('permissions' => array('anyone' => 'alrid')), 'user/jane' => array('permissions' => array('anyone' => 'alrid')))); self::$cache = new Horde_Cache(new Horde_Cache_Storage_Mock()); $group = new Horde_Share_Stub_Group(); // FIXME $GLOBALS['injector'] = new Horde_Injector(new Horde_Injector_TopLevel()); $GLOBALS['injector']->setInstance('Horde_Group', $group); foreach (array('john', 'jane', '') as $user) { self::$_shares[$user] = new Horde_Share_Kolab('mnemo', $user, new Horde_Perms_Null(), $group); $factory = new Horde_Kolab_Storage_Factory(array('driver' => 'mock', 'params' => array('data' => self::$_data, 'username' => $user), 'queries' => array('list' => array(Horde_Kolab_Storage_List_Tools::QUERY_BASE => array('cache' => true), Horde_Kolab_Storage_List_Tools::QUERY_ACL => array('cache' => true), Horde_Kolab_Storage_List_Tools::QUERY_SHARE => array('cache' => true))), 'cache' => self::$cache, 'logger' => new Horde_Log_Logger())); $storage = $factory->create(); $factory->getDriver()->setGroups(array('john' => array('mygroup'))); self::$_shares[$user]->setStorage($storage); } }
/** * Retrieve the namespace information for this connection. * * @return Horde_Kolab_Storage_Folder_Namespace The initialized namespace handler. */ public function getNamespace() { if ($this->_namespace === null) { if (isset($this->_params['namespaces'])) { $this->_namespace = $this->_factory->createNamespace('config', $this->getAuth(), $this->_params['namespaces']); } else { $this->_namespace = $this->_factory->createNamespace('fixed', $this->getAuth()); } } return $this->_namespace; }
/** * Get a folder list object for a "system" user. * * @param string $type The type of system user. * * @return Horde_Kolab_Storage_List The handler for the list of folders * present in the Kolab backend. */ public function getSystemList($type) { if (!isset($this->_params['system'][$type])) { if (!isset($this->_params['system'][''])) { throw new Horde_Kolab_Storage_Exception('No system users are available!'); } else { $params = $this->_params['system']['']; } } else { $params = $this->_params['system'][$type]; } return $this->getList($this->_factory->createDriver(array('params' => $params))); }
/** * Synchronize any changes with the History driver. * * @param array $params Additional parameters: * - changes: (array) An array of arrays keyed by backend id containing * information about each change. If not present, * triggers a full history sync. * - is_reset: (boolean) If true, indicates that UIDVALIDITY changed. */ public function synchronize($params = array()) { $user = $this->_data->getAuth(); $folder = $this->_data->getPath(); // check if IMAP uidvalidity changed $is_reset = !empty($params['is_reset']); if (isset($params['changes']) && !$is_reset) { $added = $params['changes'][Horde_Kolab_Storage_Folder_Stamp::ADDED]; $deleted = $params['changes'][Horde_Kolab_Storage_Folder_Stamp::DELETED]; if (!empty($added) || !empty($deleted)) { if (!($prefix = $this->_factory->getHistoryPrefixGenerator()->getPrefix($this->_data))) { // Abort history update if we can't determine the prefix. return; } $this->_logger->debug(sprintf('[KOLAB_STORAGE] Incremental Horde_History update for user: %s, folder: %s, prefix: %s', $user, $folder, $prefix)); } foreach ($added as $bid => $object) { $this->_updateLog($prefix . $object['uid'], $bid); } foreach ($deleted as $bid => $object_uid) { // Check if the object is really gone from the folder. // Otherwise we just deleted a duplicated object or updated the original one. // (An update results in an ADDED + DELETED folder action) if ($this->_data->objectIdExists($object_uid) == true) { $this->_logger->debug(sprintf('[KOLAB_STORAGE] Object still existing: object: %s, vanished IMAP uid: %d. Skipping delete from Horde_History.', $object_uid, $bid)); continue; } $this->_logger->debug(sprintf('[KOLAB_STORAGE] Object deleted: uid: %d -> %s, logging in Horde_History.', $bid, $object_uid)); $this->_history->log($prefix . $object_uid, array('action' => 'delete', 'bid' => $bid), true); } } else { // Full sync. Either our timestamp is too old or the IMAP // uidvalidity changed. if (!($prefix = $this->_factory->getHistoryPrefixGenerator()->getPrefix($this->_data))) { return; } $this->_logger->debug(sprintf('[KOLAB_STORAGE] Full Horde_History sync for user: %s, folder: %s, is_reset: %d, prefix: %s', $user, $folder, $is_reset, $prefix)); $this->_completeSynchronization($prefix, $is_reset); } }
public function testHistoryInject() { $history = new Horde_History_Mock('test'); $factory = new Horde_Kolab_Storage_Factory(array('history' => $history)); $this->assertSame($history, $factory->createHistory('test')); }
private function _createStorage($data = array()) { $factory = new Horde_Kolab_Storage_Factory(array('driver' => 'mock', 'params' => array('data' => array_merge(array('format' => 'brief', 'user/test' => null), $data), 'username' => '*****@*****.**'), 'queryset' => array('list' => array('queryset' => 'horde'), 'data' => array('queryset' => 'horde')), 'cache' => new Horde_Cache(new Horde_Cache_Storage_Mock()), 'logger' => $this->getMock('Horde_Log_Logger'))); return $factory->create(); }
private function _getBrokenStore($params = array()) { $default_params = array('cache' => new Horde_Cache(new Horde_Cache_Storage_Mock()), 'driver' => 'mock', 'params' => array('username' => 'test', 'host' => 'localhost', 'port' => 143, 'data' => $this->getMockData(array('user/test' => null, 'user/test/Notes' => array('t' => 'note.default', 'm' => array(1 => array('stream' => fopen(__DIR__ . '/../../fixtures/broken_note.eml', 'r')))))))); $params = array_merge($default_params, $params); $factory = new Horde_Kolab_Storage_Factory($params); $driver = $factory->createDriver(); $storage = $this->createStorage($driver, $factory); return $storage->getData('INBOX/Notes'); }
/** * Parse the content of a Kolab object into a Horde_Push element. * * @param string $argument A single command line argument (without the scheme argument). * @param array $conf The configuration. * * @return Horde_Push The element to be pushed. */ private function _parseKolab($argument, $conf) { if (!interface_exists('Horde_Kolab_Storage')) { throw new Horde_Push_Exception('The Horde_Kolab_Storage package is missing!'); } $elements = explode('/', $argument); $id = array_pop($elements); $path = join('/', $elements); $factory = new Horde_Kolab_Storage_Factory($conf['kolab']); return $this->_createFromData($factory->create()->getData($path, 'note')->getObject($id)); }
/** * Return the driver for the Kolab storage backend. * * @param mixed $options An array of options. * * @return Horde_Kolab_Storage The storage handler. */ private function _getStorage($options) { if (empty($options['driver'])) { return; } if ($options['driver'] == 'mock') { $options['data'] = array('format' => 'brief', 'user/test' => null); } $params = array('driver' => $options['driver'], 'params' => $options, 'logger' => isset($options['log']) ? $options['log'] : null, 'timelog' => isset($options['log']) && isset($options['timed']) ? $options['log'] : null); if (empty($options['nocache'])) { $params['cache'] = array('prefix' => 'kolab_cache_', 'dir' => '/tmp/kolab', 'lifetime' => 0); } $factory = new Horde_Kolab_Storage_Factory($params); return $factory->create(); }
private function _getDriverWithData($data) { $factory = new Horde_Kolab_Storage_Factory(array('driver' => 'mock', 'queries' => array('list' => array(Horde_Kolab_Storage_List_Tools::QUERY_BASE => array('cache' => true), Horde_Kolab_Storage_List_Tools::QUERY_ACL => array('cache' => true), Horde_Kolab_Storage_List_Tools::QUERY_SHARE => array('cache' => true))), 'params' => $data, 'cache' => new Horde_Cache(new Horde_Cache_Storage_Mock()), 'logger' => new Horde_Log_Logger())); $driver = $this->_getDriver('kronolith'); $this->storage = $factory->create(); $this->list = $this->storage->getList(); $this->list->getListSynchronization()->synchronize(); $driver->setStorage($this->storage); return $driver; }
/** * Return the Horde_Kolab_Storage:: instance. * * @return Horde_Kolab_Storage The storage handler. */ public function create() { $configuration = $this->_injector->getInstance('Horde_Kolab_Storage_Configuration'); // Cache configuration $cache = !empty($configuration['cache']) ? $configuration['cache'] : 'Mock'; switch ($cache) { case 'Horde': $cacheob = $this->_injector->getInstance('Horde_Cache'); break; case 'Mock': default: $cacheob = new Horde_Cache(new Horde_Cache_Storage_Mock(), array('compress' => true)); } $params = array('driver' => 'horde', 'params' => array('host' => $configuration['server'], 'username' => $GLOBALS['registry']->getAuth(), 'password' => $GLOBALS['registry']->getAuthCredential('password'), 'port' => $configuration['port'], 'secure' => $configuration['secure'], 'debug' => isset($configuration['debug']) ? $configuration['debug'] : null, 'cache' => array('backend' => new Horde_Imap_Client_Cache_Backend_Cache(array('cacheob' => $cacheob)))), 'queries' => array('list' => array(Horde_Kolab_Storage_List_Tools::QUERY_BASE => array('cache' => true), Horde_Kolab_Storage_List_Tools::QUERY_ACL => array('cache' => true), Horde_Kolab_Storage_List_Tools::QUERY_SHARE => array('cache' => true))), 'queryset' => array('data' => array('queryset' => 'horde')), 'logger' => $this->_injector->getInstance('Horde_Log_Logger'), 'log' => array('debug'), 'cache' => $this->_injector->getInstance('Horde_Cache')); // Check if the history system is enabled try { $history = $this->_injector->getInstance('Horde_History'); $params['history'] = $history; $params['history_prefix_generator'] = new Horde_Core_Kolab_Storage_HistoryPrefix(); } catch (Horde_Exception $e) { } if (!empty($configuration['strategy'])) { $classname = 'Horde_Kolab_Storage_Synchronization_' . basename($configuration['strategy']); if (!class_exists($classname)) { throw new Horde_Exception(sprintf('Class %s not found.', $classname)); } $params['sync_strategy'] = new $classname(); } $factory = new Horde_Kolab_Storage_Factory($params); return $factory->create(); }
protected function getDataStorage($data, $params = array()) { $factory = new Horde_Kolab_Storage_Factory(array_merge(array('driver' => 'mock', 'params' => $data, 'logger' => $this->getMock('Horde_Log_Logger')), $params)); return $factory->create(); }