[Pkg-owncloud-commits] [php-sabredav] 26/31: Automatically exposing a 'ctag' if we have a token available that can take that role.

David Prévot taffit at moszumanska.debian.org
Wed Aug 27 22:33:07 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository php-sabredav.

commit e5ea11bcb8319f32275db05b2711c11bbb9c8ef2
Author: Evert Pot <evert at rooftopsolutions.nl>
Date:   Wed Aug 27 18:23:34 2014 +0200

    Automatically exposing a 'ctag' if we have a token available that can take that role.
    
    Fixes #496
---
 ChangeLog.md                              |   2 +
 lib/DAV/CorePlugin.php                    |  32 +++++++++-
 tests/Sabre/CalDAV/CalendarTest.php       |  10 ++-
 tests/Sabre/CardDAV/AddressBookTest.php   |   9 ++-
 tests/Sabre/DAV/SyncTokenPropertyTest.php | 100 ++++++++++++++++++++++++++++++
 5 files changed, 150 insertions(+), 3 deletions(-)

diff --git a/ChangeLog.md b/ChangeLog.md
index 08781d7..c80b482 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -6,6 +6,8 @@ ChangeLog
 
 * #483: typo in calendars creation for PostgreSQL.
 * #487: Locks are now automatically removed after a node has been deleted.
+* #496: Improve CalDAV and CardDAV sync when there is no webdav-sync support.
+* Added: Automatically mapping internal sync-tokens to getctag.
 
 2.0.3 (2014-07-14)
 ------------------
diff --git a/lib/DAV/CorePlugin.php b/lib/DAV/CorePlugin.php
index baba1aa..97c587d 100644
--- a/lib/DAV/CorePlugin.php
+++ b/lib/DAV/CorePlugin.php
@@ -863,7 +863,37 @@ class CorePlugin extends ServerPlugin {
 
         $propFind->handle('{http://calendarserver.org/ns/}getctag', function() use ($propFind) {
 
-            return $propFind->get('{http://sabredav.org/ns}sync-token');
+            // If we already have a sync-token from the current propFind
+            // request, we can re-use that.
+            $val = $propFind->get('{http://sabredav.org/ns}sync-token');
+            if ($val) return $val;
+
+            $val = $propFind->get('{DAV:}sync-token');
+            if ($val && is_scalar($val)) {
+                return $val;
+            }
+            if ($val && $val instanceof Property\IHref) {
+                return substr($val->getHref(), strlen(Sync\Plugin::SYNCTOKEN_PREFIX));
+            }
+
+            // If we got here, the earlier two properties may simply not have
+            // been part of the earlier request. We're going to fetch them.
+            $result = $this->server->getProperties($propFind->getPath(), [
+                '{http://sabredav.org/ns}sync-token',
+                '{DAV:}sync-token',
+            ]);
+
+            if (isset($result['{http://sabredav.org/ns}sync-token'])) {
+                return $result['{http://sabredav.org/ns}sync-token'];
+            }
+            if (isset($result['{DAV:}sync-token'])) {
+                $val = $result['{DAV:}sync-token'];
+                if (is_scalar($val)) {
+                    return $val;
+                } elseif ($val instanceof Property\IHref) {
+                    return substr($val->getHref(), strlen(Sync\Plugin::SYNCTOKEN_PREFIX));
+                }
+            }
 
         });
 
diff --git a/tests/Sabre/CalDAV/CalendarTest.php b/tests/Sabre/CalDAV/CalendarTest.php
index a5f3e3d..95579f9 100644
--- a/tests/Sabre/CalDAV/CalendarTest.php
+++ b/tests/Sabre/CalDAV/CalendarTest.php
@@ -10,7 +10,7 @@ require_once 'Sabre/CalDAV/TestUtil.php';
 class CalendarTest extends \PHPUnit_Framework_TestCase {
 
     /**
-     * @var Sabre\CalDAV\Backend_PDO
+     * @var Sabre\CalDAV\Backend\PDO
      */
     protected $backend;
     protected $principalBackend;
@@ -261,6 +261,14 @@ class CalendarTest extends \PHPUnit_Framework_TestCase {
         $this->assertEquals(2, $this->calendar->getSyncToken());
 
     }
+    function testGetSyncToken2() {
+
+        $calendar = new Calendar(new Backend\Mock([],[]), [
+            '{DAV:}sync-token' => 2
+        ]);
+        $this->assertEquals(2, $this->calendar->getSyncToken());
+
+    }
 
     function testGetSyncTokenNoSyncSupport() {
 
diff --git a/tests/Sabre/CardDAV/AddressBookTest.php b/tests/Sabre/CardDAV/AddressBookTest.php
index eb6808a..397e728 100644
--- a/tests/Sabre/CardDAV/AddressBookTest.php
+++ b/tests/Sabre/CardDAV/AddressBookTest.php
@@ -165,7 +165,6 @@ class AddressBookTest extends \PHPUnit_Framework_TestCase {
 
         $this->assertNull(null, $this->ab->getSyncToken());
 
-
     }
     function testGetChangesNoSyncSupport() {
 
@@ -182,6 +181,14 @@ class AddressBookTest extends \PHPUnit_Framework_TestCase {
         $this->assertEquals(2, $ab->getSyncToken());
     }
 
+    function testGetSyncToken2() {
+
+        if (!SABRE_HASSQLITE) {
+            $this->markTestSkipped('Sqlite is required for this test to run');
+        }
+        $ab = new AddressBook(TestUtil::getBackend(), [ 'id' => 1, '{http://sabredav.org/ns}sync-token' => 2]);
+        $this->assertEquals(2, $ab->getSyncToken());
+    }
 
     function testGetChanges() {
 
diff --git a/tests/Sabre/DAV/SyncTokenPropertyTest.php b/tests/Sabre/DAV/SyncTokenPropertyTest.php
new file mode 100644
index 0000000..01ef94c
--- /dev/null
+++ b/tests/Sabre/DAV/SyncTokenPropertyTest.php
@@ -0,0 +1,100 @@
+<?php
+
+namespace Sabre\DAV;
+
+class SyncTokenPropertyTest extends \Sabre\DAVServerTest {
+
+    /**
+     * The assumption in these tests is that a PROPFIND is going on, and to
+     * fetch the sync-token, the event handler is just able to use the existing
+     * result.
+     *
+     * @dataProvider data
+     */
+    function testAlreadyThere1($name, $value) {
+
+        $propFind = new PropFind('foo', [
+            '{http://calendarserver.org/ns/}getctag',
+            $name,
+        ]);
+
+        $propFind->set($name, $value);
+        $corePlugin = new CorePlugin();
+        $corePlugin->propFindLate($propFind, new SimpleCollection('hi'));
+
+        $this->assertEquals("hello", $propFind->get('{http://calendarserver.org/ns/}getctag'));
+
+    }
+
+    /**
+     * In these test-cases, the plugin is forced to do a local propfind to
+     * fetch the items.
+     *
+     * @dataProvider data
+     */
+    function testRefetch($name, $value) {
+
+        $this->server->tree = new ObjectTree(
+            new SimpleCollection('root', [
+                new Mock\PropertiesCollection(
+                    'foo',
+                    [],
+                    [$name => $value]
+                )
+            ])
+        );
+        $propFind = new PropFind('foo', [
+            '{http://calendarserver.org/ns/}getctag',
+            $name,
+        ]);
+
+        $corePlugin = $this->server->getPlugin('core');
+        $corePlugin->propFindLate($propFind, new SimpleCollection('hi'));
+
+        $this->assertEquals("hello", $propFind->get('{http://calendarserver.org/ns/}getctag'));
+
+    }
+
+    function testNoData() {
+
+        $this->server->tree = new ObjectTree(
+            new SimpleCollection('root', [
+                new Mock\PropertiesCollection(
+                    'foo',
+                    [],
+                    []
+                )
+            ])
+        );
+
+        $propFind = new PropFind('foo', [
+            '{http://calendarserver.org/ns/}getctag',
+        ]);
+
+        $corePlugin = $this->server->getPlugin('core');
+        $corePlugin->propFindLate($propFind, new SimpleCollection('hi'));
+
+        $this->assertNull($propFind->get('{http://calendarserver.org/ns/}getctag'));
+
+    }
+
+    function data() {
+
+        return [
+            [
+                '{http://sabredav.org/ns}sync-token',
+                "hello"
+            ],
+            [
+                '{DAV:}sync-token',
+                "hello"
+            ],
+            [
+                '{DAV:}sync-token',
+                new Property\Href(Sync\Plugin::SYNCTOKEN_PREFIX . "hello", false)
+            ]
+        ];
+
+    }   
+
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git



More information about the Pkg-owncloud-commits mailing list