Skip to content

Commit b291d9b

Browse files
authored
Merge pull request #10842 from nextcloud/bugfix/9339/initial_collection_sync_caldav_carddav
LIMIT is no column but a SQL keyword, allow limit on initial sync
2 parents ab92078 + 9f6dd51 commit b291d9b

7 files changed

Lines changed: 76 additions & 1 deletion

File tree

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
'OCA\\DAV\\Direct\\DirectHome' => $baseDir . '/../lib/Direct/DirectHome.php',
148148
'OCA\\DAV\\Direct\\Server' => $baseDir . '/../lib/Direct/Server.php',
149149
'OCA\\DAV\\Direct\\ServerFactory' => $baseDir . '/../lib/Direct/ServerFactory.php',
150+
'OCA\\DAV\\Exception\\UnsupportedLimitOnInitialSyncException' => $baseDir . '/../lib/Exception/UnsupportedLimitOnInitialSyncException.php',
150151
'OCA\\DAV\\Files\\BrowserErrorPagePlugin' => $baseDir . '/../lib/Files/BrowserErrorPagePlugin.php',
151152
'OCA\\DAV\\Files\\FileSearchBackend' => $baseDir . '/../lib/Files/FileSearchBackend.php',
152153
'OCA\\DAV\\Files\\FilesHome' => $baseDir . '/../lib/Files/FilesHome.php',

apps/dav/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class ComposerStaticInitDAV
162162
'OCA\\DAV\\Direct\\DirectHome' => __DIR__ . '/..' . '/../lib/Direct/DirectHome.php',
163163
'OCA\\DAV\\Direct\\Server' => __DIR__ . '/..' . '/../lib/Direct/Server.php',
164164
'OCA\\DAV\\Direct\\ServerFactory' => __DIR__ . '/..' . '/../lib/Direct/ServerFactory.php',
165+
'OCA\\DAV\\Exception\\UnsupportedLimitOnInitialSyncException' => __DIR__ . '/..' . '/../lib/Exception/UnsupportedLimitOnInitialSyncException.php',
165166
'OCA\\DAV\\Files\\BrowserErrorPagePlugin' => __DIR__ . '/..' . '/../lib/Files/BrowserErrorPagePlugin.php',
166167
'OCA\\DAV\\Files\\FileSearchBackend' => __DIR__ . '/..' . '/../lib/Files/FileSearchBackend.php',
167168
'OCA\\DAV\\Files\\FilesHome' => __DIR__ . '/..' . '/../lib/Files/FilesHome.php',

apps/dav/lib/CalDAV/CachedSubscription.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
namespace OCA\DAV\CalDAV;
2525

26+
use OCA\DAV\Exception\UnsupportedLimitOnInitialSyncException;
2627
use Sabre\CalDAV\Backend\BackendInterface;
2728
use Sabre\DAV\Exception\MethodNotAllowed;
2829
use Sabre\DAV\Exception\NotFound;
@@ -195,4 +196,15 @@ public function childExists($name):bool {
195196
public function calendarQuery(array $filters):array {
196197
return $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
197198
}
199+
200+
/**
201+
* @inheritDoc
202+
*/
203+
public function getChanges($syncToken, $syncLevel, $limit = null) {
204+
if (!$syncToken && $limit) {
205+
throw new UnsupportedLimitOnInitialSyncException();
206+
}
207+
208+
return parent::getChanges($syncToken, $syncLevel, $limit);
209+
}
198210
}

apps/dav/lib/CalDAV/Calendar.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
namespace OCA\DAV\CalDAV;
2828

2929
use OCA\DAV\DAV\Sharing\IShareable;
30+
use OCA\DAV\Exception\UnsupportedLimitOnInitialSyncException;
3031
use OCP\IConfig;
3132
use OCP\IL10N;
3233
use Sabre\CalDAV\Backend\BackendInterface;
@@ -339,4 +340,14 @@ public function isSubscription() {
339340
return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']);
340341
}
341342

343+
/**
344+
* @inheritDoc
345+
*/
346+
public function getChanges($syncToken, $syncLevel, $limit = null) {
347+
if (!$syncToken && $limit) {
348+
throw new UnsupportedLimitOnInitialSyncException();
349+
}
350+
351+
return parent::getChanges($syncToken, $syncLevel, $limit);
352+
}
342353
}

apps/dav/lib/CardDAV/AddressBook.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
namespace OCA\DAV\CardDAV;
2424

2525
use OCA\DAV\DAV\Sharing\IShareable;
26+
use OCA\DAV\Exception\UnsupportedLimitOnInitialSyncException;
2627
use OCP\IL10N;
2728
use Sabre\CardDAV\Backend\BackendInterface;
2829
use Sabre\CardDAV\Card;
@@ -219,4 +220,12 @@ private function canWrite() {
219220
}
220221
return true;
221222
}
223+
224+
public function getChanges($syncToken, $syncLevel, $limit = null) {
225+
if (!$syncToken && $limit) {
226+
throw new UnsupportedLimitOnInitialSyncException();
227+
}
228+
229+
return parent::getChanges($syncToken, $syncLevel, $limit);
230+
}
222231
}

apps/dav/lib/CardDAV/CardDavBackend.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ function getChangesForAddressBook($addressBookId, $syncToken, $syncLevel, $limit
814814

815815
$query = "SELECT `uri`, `operation` FROM `*PREFIX*addressbookchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `addressbookid` = ? ORDER BY `synctoken`";
816816
if ($limit>0) {
817-
$query .= " `LIMIT` " . (int)$limit;
817+
$query .= " LIMIT " . (int)$limit;
818818
}
819819

820820
// Fetching all changes
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (c) 2019 Georg Ehrke
5+
*
6+
* @author Georg Ehrke <oc.list@georgehrke.com>
7+
*
8+
* @license AGPL-3.0
9+
*
10+
* This code is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Affero General Public License, version 3,
12+
* as published by the Free Software Foundation.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License, version 3,
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>
21+
*
22+
*/
23+
namespace OCA\DAV\Exception;
24+
25+
use Sabre\DAV\Exception\InsufficientStorage;
26+
use Sabre\DAV\Server;
27+
28+
/**
29+
* Class UnsupportedLimitOnInitialSyncException
30+
*
31+
* @package OCA\DAV\Exception
32+
*/
33+
class UnsupportedLimitOnInitialSyncException extends InsufficientStorage {
34+
35+
/**
36+
* @inheritDoc
37+
*/
38+
public function serialize(Server $server, \DOMElement $errorNode) {
39+
$errorNode->appendChild($errorNode->ownerDocument->createElementNS('DAV:', 'd:number-of-matches-within-limits'));
40+
}
41+
}

0 commit comments

Comments
 (0)