diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index d886704a3345f..404b3042bf1e9 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -897,14 +897,16 @@ public function getChangesForAddressBook($addressBookId, $syncToken, $syncLevel, ->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 1c88ccd73dada..53931dd1675f9 100644 --- a/apps/federation/lib/SyncFederationAddressBooks.php +++ b/apps/federation/lib/SyncFederationAddressBooks.php @@ -52,6 +52,7 @@ public function syncThemAll(\Closure $callback) { 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 @@ public function syncThemAll(\Closure $callback) { 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;