/** * 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 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); } }
/** * Synchronize the list information with the information from the backend. * * @see Horde_Kolab_Storage_Query * * @return NULL */ public function synchronize($params = array()) { $params = array_merge(array('logger' => $this->_logger), $params); $this->_data->synchronize($params); $this->_logger->debug(sprintf('Synchronized data cache for %s.', $this->_data->getPath())); }