Exemplo n.º 1
0
 /**
  * validate sync key
  * 
  * @param ActiveSync_Model_Device $_device
  * @param $_counter
  * @param $_class
  * @param $_collectionId
  * @return boolean
  */
 public function validateSyncKey(ActiveSync_Model_Device $_device, $_counter, $_class, $_collectionId = NULL)
 {
     $type = $_collectionId !== NULL ? $_class . '-' . $_collectionId : $_class;
     $syncState = new ActiveSync_Model_SyncState(array('device_id' => $_device->getId(), 'counter' => $_counter, 'type' => $type));
     try {
         $syncState = $this->_syncStateBackend->get($syncState);
     } catch (ActiveSync_Exception_SyncStateNotFound $asessnf) {
         return false;
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($syncState->toArray(), true));
     }
     // check if this was the latest syncKey
     try {
         $otherSyncState = clone $syncState;
         $otherSyncState->counter++;
         $otherSyncState = $this->_syncStateBackend->get($otherSyncState);
         if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
             Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' found more recent synckey');
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
             Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' ' . print_r($otherSyncState->toArray(), true));
         }
         // undelete marked entries
         $contentStateFilter = new ActiveSync_Model_ContentStateFilter(array(array('field' => 'device_id', 'operator' => 'equals', 'value' => $_device->getId()), array('field' => 'class', 'operator' => 'equals', 'value' => $_class), array('field' => 'collectionid', 'operator' => 'equals', 'value' => $_collectionId), array('field' => 'is_deleted', 'operator' => 'equals', 'value' => true)));
         $stateIds = $this->_contentStateBackend->search($contentStateFilter, null, true);
         $this->_contentStateBackend->updateMultiple($stateIds, array('is_deleted' => 0));
         // remove entries added during latest sync
         $contentStateFilter = new ActiveSync_Model_ContentStateFilter(array(array('field' => 'device_id', 'operator' => 'equals', 'value' => $_device->getId()), array('field' => 'class', 'operator' => 'equals', 'value' => $_class), array('field' => 'collectionid', 'operator' => 'equals', 'value' => $_collectionId), array('field' => 'creation_time', 'operator' => 'after', 'value' => $syncState->lastsync)));
         $stateIds = $this->_contentStateBackend->search($contentStateFilter, null, true);
         $this->_contentStateBackend->delete($stateIds);
     } catch (ActiveSync_Exception_SyncStateNotFound $asessnf) {
         // finaly delete all entries marked for removal
         $contentStateFilter = new ActiveSync_Model_ContentStateFilter(array(array('field' => 'device_id', 'operator' => 'equals', 'value' => $_device->getId()), array('field' => 'class', 'operator' => 'equals', 'value' => $_class), array('field' => 'collectionid', 'operator' => 'equals', 'value' => $_collectionId), array('field' => 'is_deleted', 'operator' => 'equals', 'value' => true)));
         $stateIds = $this->_contentStateBackend->search($contentStateFilter, null, true);
         $this->_contentStateBackend->delete($stateIds);
     }
     // remove all other synckeys
     $this->_syncStateBackend->deleteOther($syncState);
     if (!empty($syncState->pendingdata)) {
         $syncState->pendingdata = Zend_Json::decode($syncState->pendingdata);
     }
     return $syncState;
 }