0012512: WebDAV - SyncToken - check if synctoken is valid
authorPaul Mehrer <p.mehrer@metaways.de>
Wed, 11 Jan 2017 16:16:49 +0000 (17:16 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 16 Jan 2017 07:45:48 +0000 (08:45 +0100)
check if the current synctoken actually still exists
in the db and not just check if it makes sense

Change-Id: Ie0521f1a49ff2a2d923c365e36c421145741b057
Reviewed-on: http://gerrit.tine20.com/customers/4070
Tested-by: Philipp Schüle <p.schuele@metaways.de>
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Tinebase/WebDav/Plugin/SyncTokenTest.php
tine20/Calendar/Frontend/WebDAV/Container.php
tine20/Tinebase/Container.php
tine20/Tinebase/WebDav/Container/Abstract.php

index 2eeea42..45bd18e 100644 (file)
@@ -135,7 +135,7 @@ class Tinebase_WebDav_Plugin_SyncTokenTest extends Tinebase_WebDav_Plugin_Abstra
     {
         $body = '<?xml version="1.0" encoding="UTF-8"?>
                 <A:sync-collection xmlns:A="DAV:">
-                    <A:sync-token>http://tine20.net/ns/sync/0</A:sync-token>
+                    <A:sync-token>http://tine20.net/ns/sync/-1</A:sync-token>
                     <A:sync-level>1</A:sync-level>
                     <A:prop>
                         <A:getetag/>
index f86ce4c..eb29651 100644 (file)
@@ -477,7 +477,9 @@ class Calendar_Frontend_WebDAV_Container extends Tinebase_WebDav_Container_Abstr
      */
     public function getChanges($syncToken)
     {
-        $result = parent::getChanges($syncToken);
+        if (null === ($result = parent::getChanges($syncToken))) {
+            return $result;
+        }
 
         $newResult = array();
         $backend = Calendar_Controller_Event::getInstance()->getBackend();
index 18bfa71..5d12d68 100644 (file)
@@ -1714,16 +1714,26 @@ class Tinebase_Container extends Tinebase_Backend_Sql_Abstract
      * @param integer $lastContentSeq
      * @return Tinebase_Record_RecordSet
      */
-    public function getContentHistory($containerId, $lastContentSeq = 0)
+    public function getContentHistory($containerId, $lastContentSeq = -1)
     {
         $filter = new Tinebase_Model_ContainerContentFilter(array(
             array('field' => 'container_id', 'operator' => 'equals',  'value' => Tinebase_Model_Container::convertContainerIdToInt($containerId)),
-            array('field' => 'content_seq',  'operator' => 'greater', 'value' => $lastContentSeq),
+            array('field' => 'content_seq',  'operator' => 'greater', 'value' => ($lastContentSeq == -1 ? $lastContentSeq : $lastContentSeq - 1)),
         ));
         $pagination = new Tinebase_Model_Pagination(array(
             'sort' => 'content_seq'
         ));
         $result = $this->getContentBackend()->search($filter, $pagination);
+        if ($lastContentSeq != -1) {
+            if ($result->count() === 0) {
+                return null;
+            }
+            $firstRecord = $result->getFirstRecord();
+            if ($firstRecord->content_seq != $lastContentSeq) {
+                return null;
+            }
+            $result->removeRecord($firstRecord);
+        }
         return $result;
     }
 
index 5e15bf9..9bfe301 100644 (file)
@@ -567,6 +567,9 @@ abstract class Tinebase_WebDav_Container_Abstract extends \Sabre\DAV\Collection
         );
 
         $resultSet = Tinebase_Container::getInstance()->getContentHistory($this->_container, $syncToken);
+        if (null === $resultSet) {
+            return null;
+        }
         foreach($resultSet as $contentModel) {
             switch($contentModel->action) {
                 case Tinebase_Model_ContainerContent::ACTION_DELETE: