diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Data/Query/History/Base.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Data/Query/History/Base.php index 19978c1b971..0585f2f9065 100644 --- a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Data/Query/History/Base.php +++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Data/Query/History/Base.php @@ -86,12 +86,13 @@ public function setLogger(Horde_Log_Logger $logger) } /** - * Synchronize the preferences information with the information from the - * backend. + * 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. + * 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()) { @@ -112,7 +113,6 @@ public function synchronize($params = array()) if (empty($prefix)) { return; } - $this->_logger->debug(sprintf( 'History: Incremental update for user: %s, folder: %s, prefix: %s', $user, $folder, $prefix) @@ -122,6 +122,7 @@ public function synchronize($params = array()) 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. @@ -138,45 +139,41 @@ public function synchronize($params = array()) $bid, $object_uid) ); $this->_history->log( - $prefix.$object_uid, array('action' => 'delete', 'bid' => $bid), true + $prefix . $object_uid, array('action' => 'delete', 'bid' => $bid), true ); } } else { + // Full sync. Either our timestamp is too old or the IMAP + // uidvalidity changed. $prefix = $this->_constructHistoryPrefix(); if (empty($prefix)) { return; } - $this->_logger->debug(sprintf( 'History: Full history sync for user: %s, folder: %s, is_reset: %d, prefix: %s', $user, $folder, $is_reset, $prefix) ); - - // Full sync. Either our timestamp is too old - // or the IMAP uidvalidity changed $this->_completeSynchronization($prefix, $is_reset); } } /** * Perform a complete synchronization. - * Also markes stale history entries as 'deleted'. + * Also marks stale history entries as 'deleted'. * - * @param string $prefix Horde_History prefix - * @param boolean $is_reset Flag to indicate if the UIDVALIDITY changed - * - * @return NULL + * @param string $prefix Horde_History prefix + * @param boolean $is_reset Flag to indicate if the UIDVALIDITY changed */ - private function _completeSynchronization($prefix, $is_reset) + protected function _completeSynchronization($prefix, $is_reset) { $seen_objects = array(); foreach ($this->_data->getObjectToBackend() as $object => $bid) { - $full_id = $prefix.$object; + $full_id = $prefix . $object; $this->_updateLog($full_id, $bid, $is_reset); $seen_objects[$full_id] = true; } - // cut of last ':' + // cut off last ':' $search_prefix = substr($prefix, 0, -1); // clean up history database: Mark stale entries as deleted @@ -247,7 +244,7 @@ private function _constructHistoryPrefix() return ''; } - $this->_prefix = $app.':'.$share_id.':'; + $this->_prefix = $app . ':' . $share_id . ':'; return $this->_prefix; } @@ -255,7 +252,7 @@ private function _constructHistoryPrefix() /** * Map Kolab object type to horde application name. * - * @param string $type Kolab object type + * @param string $type Kolab object type * * @return string The horde application name. Empty string if unknown */ @@ -277,14 +274,11 @@ private function _type2app($type) /** * Update the history log for an object. * - * @param string $object The object ID. - * @param string $bid The backend ID of - * the object. - * @param bool $force Force update - * - * @return NULL + * @param string $object The object ID. + * @param string $bid The backend ID of the object. + * @param boolean $force Force update */ - private function _updateLog($object, $bid, $force=false) + protected function _updateLog($object, $bid, $force = false) { $last = $this->_history->getLatestEntry($object); if ($last === false) { @@ -321,4 +315,5 @@ private function _updateLog($object, $bid, $force=false) } } } + } diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Data/Query/History/Cache.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Data/Query/History/Cache.php index 0df8342db9e..cae2ceab625 100644 --- a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Data/Query/History/Cache.php +++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Data/Query/History/Cache.php @@ -39,8 +39,6 @@ class Horde_Kolab_Storage_Data_Query_History_Cache * - last_sync: (integer) Timestamp containing the time of last sync. * - changes: (array) An array of arrays keyed by backend id * containing information about each change. - * - * @return NULL */ public function synchronize($params = array()) { @@ -80,4 +78,5 @@ public function synchronize($params = array()) ); } } + } diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Data/BaseTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Data/BaseTest.php index 3c1d79a4c5f..2310fcfa11c 100644 --- a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Data/BaseTest.php +++ b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Data/BaseTest.php @@ -384,7 +384,7 @@ public function testModify() $object = $data->getObject('UID'); $this->assertEquals('modified', $object['summary']); } - + public function testDuplicatesAddedObjects() { $data = $this->getMessageStorage()->getData('INBOX/Notes');