aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/dav/lib/CardDAV/CardDavBackend.php12
-rw-r--r--apps/federation/lib/SyncFederationAddressBooks.php3
2 files changed, 9 insertions, 6 deletions
diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php
index d886704a334..404b3042bf1 100644
--- a/apps/dav/lib/CardDAV/CardDavBackend.php
+++ b/apps/dav/lib/CardDAV/CardDavBackend.php
@@ -897,14 +897,16 @@ class CardDavBackend implements BackendInterface, SyncSupport {
->setMaxResults($limit);
$stmt = $qb->executeQuery();
$values = $stmt->fetchAll(\PDO::FETCH_ASSOC);
- $lastID = end($values)['id'];
- $result['syncToken'] = 'init_' . $lastID . '_' . $initialSyncToken;
- $result['added'] = array_column($values, 'uri');
$stmt->closeCursor();
- $result['result_truncated'] = true;
- if (count($result['added']) < $limit) {
+ if (count($values) === 0) {
$result['syncToken'] = $initialSyncToken;
$result['result_truncated'] = false;
+ $result['added'] = [];
+ } else {
+ $lastID = end($values)['id'];
+ $result['added'] = array_column($values, 'uri');
+ $result['syncToken'] = count($result['added']) === $limit ? "init_{$lastID}_$initialSyncToken" : $initialSyncToken ;
+ $result['result_truncated'] = count($result['added']) === $limit;
}
} elseif ($syncToken) {
$qb = $this->db->getQueryBuilder();
diff --git a/apps/federation/lib/SyncFederationAddressBooks.php b/apps/federation/lib/SyncFederationAddressBooks.php
index 1c88ccd73da..53931dd1675 100644
--- a/apps/federation/lib/SyncFederationAddressBooks.php
+++ b/apps/federation/lib/SyncFederationAddressBooks.php
@@ -52,6 +52,7 @@ class SyncFederationAddressBooks {
try {
$newToken = $this->syncService->syncRemoteAddressBook($url, $cardDavUser, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties);
if ($newToken !== $syncToken) {
+ // Finish truncated initial sync.
if (strpos($newToken, 'init') !== false) {
$newToken = $this->syncTruncatedAddressBook($url, $cardDavUser, $addressBookUrl, $sharedSecret, $newToken, $targetBookId, $targetPrincipal, $targetBookProperties);
}
@@ -82,7 +83,7 @@ class SyncFederationAddressBooks {
private function syncTruncatedAddressBook(string $url, string $cardDavUser, string $addressBookUrl, string $sharedSecret, string $syncToken, int $targetBookId, string $targetPrincipal, array $targetBookProperties): string {
$newToken = $this->syncService->syncRemoteAddressBook($url, $cardDavUser, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties);
- while(strpos($newToken, 'init') !== false) {
+ while (strpos($newToken, 'init') !== false) {
$newToken = $this->syncService->syncRemoteAddressBook($url, $cardDavUser, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties);
}
return $newToken;