/** * Synchronize the query data with the information from the backend. * * @param array $params Additional parameters. * * @return NULL */ public function synchronize($params = array()) { $current = $this->getStamp(); if (!$this->_data_cache->isInitialized()) { $this->_completeSynchronization($current); return; } $previous = unserialize($this->_data_cache->getStamp()); if ($previous === false || $previous->isReset($current)) { $this->_completeSynchronization($current); return; } if (!isset($params['changes'])) { $changes = $previous->getChanges($current); $params['changes'][Horde_Kolab_Storage_Folder_Stamp::ADDED] = $this->fetch($changes[Horde_Kolab_Storage_Folder_Stamp::ADDED]); $params['changes'][Horde_Kolab_Storage_Folder_Stamp::DELETED] = $this->_data_cache->backendMap($changes[Horde_Kolab_Storage_Folder_Stamp::DELETED]); } if ($params['changes'] !== false) { $params['last_sync'] = $this->_data_cache->getLastSync(); $this->_data_cache->store($params['changes'][Horde_Kolab_Storage_Folder_Stamp::ADDED], $current, $this->getVersion(), $params['changes'][Horde_Kolab_Storage_Folder_Stamp::DELETED]); $params['current_sync'] = $this->_data_cache->getLastSync(); parent::synchronize($params); $this->_data_cache->save(); } $this->_init = true; }
/** * Synchronize the query data with the information from the backend. * * @see Horde_Kolab_Storage_Query * * In addition to the parameters of the base class(es), the following may * be passed as well: * - logger: (Horde_Log_Logger) A logger instance. * * @return NULL */ public function synchronize($params = array()) { $this->_logger = !empty($this->_logger) ? $this->_logger : (!empty($params['logger']) ? $params['logger'] : new Horde_Support_Stub()); // For logging $user = $this->getAuth(); $folder_path = $this->getPath(); if (!$this->_data_cache->isInitialized()) { $this->_logger->debug(sprintf('[KOLAB_STORAGE]: Initial folder sync: user: %s, folder: %s', $user, $folder_path)); $this->_completeSynchronization($this->getStamp()); return; } $previous = unserialize($this->_data_cache->getStamp()); $current = $this->getStamp($previous); // check if UIDVALIDITY changed $is_reset = false; if ($previous !== false) { $is_reset = $previous->isReset($current); } if ($previous === false || $is_reset) { $this->_logger->debug(sprintf('[KOLAB_STORAGE] Complete folder sync: user: %s, folder: %s, is_reset: %d', $user, $folder_path, $is_reset)); $this->_completeSynchronization($current); return; } if (!isset($params['changes'])) { $changes = $previous->getChanges($current); $params['changes'][Horde_Kolab_Storage_Folder_Stamp::ADDED] = $this->fetch($changes[Horde_Kolab_Storage_Folder_Stamp::ADDED]); $params['changes'][Horde_Kolab_Storage_Folder_Stamp::DELETED] = $this->_data_cache->backendMap($changes[Horde_Kolab_Storage_Folder_Stamp::DELETED]); } if ($params['changes'] !== false) { $params['last_sync'] = $this->_data_cache->getLastSync(); $this->_data_cache->store($params['changes'][Horde_Kolab_Storage_Folder_Stamp::ADDED], $current, $this->getVersion(), $params['changes'][Horde_Kolab_Storage_Folder_Stamp::DELETED]); $params['current_sync'] = $this->_data_cache->getLastSync(); if (!empty($params['changes'][Horde_Kolab_Storage_Folder_Stamp::ADDED]) || !empty($params['changes'][Horde_Kolab_Storage_Folder_Stamp::DELETED])) { $changes_to_log = array('add' => array(), 'del' => array()); foreach ($params['changes'][Horde_Kolab_Storage_Folder_Stamp::ADDED] as $uid => $object) { $changes_to_log['add'][$uid] = $object['uid']; } foreach ($params['changes'][Horde_Kolab_Storage_Folder_Stamp::DELETED] as $uid => $object_uid) { $changes_to_log['del'][$uid] = $object_uid; } $this->_logger->debug(sprintf('[KOLAB_STORAGE] Incremental folder sync: user: %s, folder: %s, last_sync: %d, current_sync: %d, changes: %s', $user, $folder_path, $params['last_sync'], $params['current_sync'], print_r($changes_to_log, true))); } parent::synchronize($params); $this->_data_cache->save(); } $this->_init = true; }