Copyright 2011-2014 Horde LLC (http://www.horde.org/)
See the enclosed file COPYING for license information (LGPL). If you
did not receive this file, see http://www.horde.org/licenses/lgpl21.
/** * Generate a prefix for the History system for the given Kolab data. * * @param Horde_Kolab_Storage_Data $data The data object. * * @return string The History prefix. */ public static function getPrefix(Horde_Kolab_Storage_Data $data) { $app = self::_type2app($data->getType()); if (empty($app)) { Horde::log(sprintf('Unsupported app type: %s', $data->getType()), 'WARN'); return false; } // Determine share id $user = $data->getAuth(); $folder = $data->getPath(); $share_id = ''; $all_shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create($app)->listAllShares(); foreach ($all_shares as $id => $share) { if ($folder == $share->get('folder')) { $share_id = $id; break; } } // Bail out if we are unable to determine the share id. if (empty($share_id)) { Horde::log(sprintf('HISTORY: share_id not found. Can\'t compute history prefix for user: %s, folder: %s', $user, $folder), 'WARN'); return false; } return $app . ':' . $share_id . ':'; }
/** * Synchronize the provided data in case the selected synchronization * strategy requires it. * * @param Horde_Kolab_Storage_Data $data The data to synchronize. */ public function synchronizeData(Horde_Kolab_Storage_Data $data) { $data_id = $data->getId(); if ($this->hasNotBeenSynchronizedYet($data_id) || $this->syncTimeHasElapsed($data_id)) { $data->synchronize(); $_SESSION['kolab_storage']['synchronization']['data'][$data_id] = time() + $this->_interval + rand(0, $this->_random_offset); } }
/** * Synchronize the provided data in case the selected synchronization * strategy requires it. * * @param Horde_Kolab_Storage_Data $data The data to synchronize. */ public function synchronizeData(Horde_Kolab_Storage_Data $data) { $data_id = $data->getId(); if (empty($_SESSION['kolab_storage']['synchronization']['data'][$data_id])) { $data->synchronize(); $_SESSION['kolab_storage']['synchronization']['data'][$data_id] = true; } }
/** * Test storing attachments. * * @return NULL */ public function testCacheAttachmentAsContent() { $data = new Horde_Kolab_Storage_Data('contact'); $data->setFolder($this->folder); $object = array('uid' => '1', 'full-name' => 'User Name', 'email' => '*****@*****.**', 'inline-attachment' => array('test.txt'), '_attachments' => array('test.txt' => array('type' => 'text/plain', 'content' => 'test', 'name' => 'test.txt'))); $result = $data->save($object); $this->assertNoError($result); $result = $data->getObject(1); $this->assertNoError($result); $this->assertTrue(isset($result['_attachments']['test.txt'])); $this->assertEquals("test\r", $data->getAttachment($result['_attachments']['test.txt']['key'])); }
/** * Synchronize the preferences information with the information from the * backend. * * @param array $params Additional parameters. * * @return NULL */ public function synchronize($params = array()) { $stamp = $this->data->getStamp(); if (isset($params['changes'])) { foreach ($params['changes'][Horde_Kolab_Storage_Folder_Stamp::ADDED] as $bid => $object) { $this->_updateLog($object['uid'], $bid, $stamp); } foreach ($params['changes'][Horde_Kolab_Storage_Folder_Stamp::DELETED] as $bid => $object) { $this->history->log($object, array('action' => 'delete', 'bid' => $bid, 'stamp' => $stamp)); } } else { foreach ($this->data->getObjectToBackend() as $object => $bid) { $this->_updateLog($object, $bid, $stamp); } } }
/** * Synchronize the preferences information with the information from the * backend. * * @param array $params Additional parameters. * * @return NULL */ public function synchronize($params = array()) { $this->_mapping = array(); foreach ($this->_data->getObjects() as $id => $data) { $this->_mapping[$data['application']] = $id; } $this->_data_cache->setQuery(self::PREFS, $this->_mapping); }
/** * Initialize the application <-> object mapping. * * @return NULL */ private function _initMapping() { if ($this->_mapping === null) { foreach ($this->_data->getObjects() as $id => $data) { $this->_mapping[$data['application']] = $id; } } }
/** * Deletes an event. * * @param string $eventId The ID of the event to delete. * * @throws Kronolith_Exception * @throws Horde_Exception_NotFound * @throws Horde_Mime_Exception */ protected function _deleteEvent($eventId, $silent = false) { if ($eventId instanceof Kronolith_Event) { $event = $eventId; $this->synchronize(); } else { $event = $this->getEvent($eventId); } $this->_data->delete($event->uid); unset($this->_events_cache[$event->id]); /* Notify about the deleted event. */ if (!$silent) { $this->_handleNotifications($event, 'delete'); } return $event; }
/** * Perform a complete synchronization. * Also marks stale history entries as 'deleted'. * * @param string $prefix Horde_History prefix * @param boolean $is_reset Flag to indicate if the UIDVALIDITY changed */ protected function _completeSynchronization($prefix, $is_reset) { $seen_objects = array(); foreach ($this->_data->getObjectToBackend() as $object => $bid) { $full_id = $prefix . $object; $this->_updateLog($full_id, $bid, $is_reset); $seen_objects[$full_id] = true; } // cut off last ':' $search_prefix = substr($prefix, 0, -1); // clean up history database: Mark stale entries as deleted $all_entries = $this->_history->getByTimestamp('>', 0, array(), $search_prefix); foreach ($all_entries as $full_id => $db_id) { if (isset($seen_objects[$full_id])) { continue; } $last = $this->_history->getLatestEntry($full_id); if ($last === false || $last['action'] != 'delete') { $this->_logger->debug(sprintf('[KOLAB_STORAGE] Cleaning up already removed object from Horde_History: %s', $full_id)); $this->_history->log($full_id, array('action' => 'delete'), true); } } }
/** * Retrieve a handler for the data in this folder. * * @param Kolab_List $list The handler for the list of folders. * * @return Horde_Kolab_Storage_Data The data handler. */ public function getData($object_type = null, $data_version = 1) { if (empty($object_type)) { $object_type = $this->getType(); if (is_a($object_type, 'PEAR_Error')) { return $object_type; } } if ($this->tainted) { foreach ($this->_data as $data) { $data->synchronize(); } $this->tainted = false; } $key = $object_type . '|' . $data_version; if (!isset($this->_data[$key])) { if ($object_type != 'annotation') { $type = $this->getType(); } else { $type = 'annotation'; } $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; } return $this->_data[$key]; }
/** * Return a registered query. * * @param string $name The query name. * * @return Horde_Kolab_Storage_Query The requested query. * * @throws Horde_Kolab_Storage_Exception In case the requested query does * not exist. */ public function getQuery($name = null) { $query = $this->_data->getQuery($name); $query->setLogger($this->_logger); return $query; }
/** * Synchronize the provided data in case the selected synchronization * strategy requires it. Always calls the synchronize method of $data, * assuming $data will know if it needs to be synchronized or not. * * @param Horde_Kolab_Storage_Data $data The data to synchronize. */ public function synchronizeData(Horde_Kolab_Storage_Data $data) { $data->synchronize(); }
/** * Add the set of data queries. * * @param Horde_Kolab_Storage_Data $data The data. * @param array $params Additional query parameters. * * @return NULL */ public function addDataQuerySet(Horde_Kolab_Storage_Data $data, $params = array()) { foreach ($this->_data_queries as $query => $type) { if ($type === true || $type == $data->getType()) { $this->_addDataQuery($data, $query, $params); } } }
/** * Fetch any additional parameters required when creating data queries. * * @param Horde_Kolab_Storage_Data $data The data. * * @return array The parameters for data queries. */ protected function _getDataQueryParameters(Horde_Kolab_Storage_Data $data) { return array('cache' => $this->_cache->getDataCache($data->getIdParameters())); }
/** * Return a registered query. * * @param string $name The query name. * * @return Horde_Kolab_Storage_Query The requested query. * * @throws Horde_Kolab_Storage_Exception In case the requested query does * not exist. */ public function getQuery($name = null) { return $this->_data->getQuery($name); }
/** * Generate a prefix for the History system for the given Kolab data. * * @param Horde_Kolab_Storage_Data $data The data object. * * @return string The History prefix. */ public static function getPrefix(Horde_Kolab_Storage_Data $data) { $app = empty(self::$_map[$data->getType()]) ? false : self::$_map[$data->getType()]; return empty($app) ? false : sprintf('%s:internal_id:', $app); }