Skip to content

Commit ef45c01

Browse files
hamza221AndyScherzinger
authored andcommitted
fixup! feat(cardav): support result truncation for addressbook federation
Signed-off-by: Hamza Mahjoubi <hamzamahjoubi221@gmail.com>
1 parent 71a6837 commit ef45c01

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

apps/dav/lib/CardDAV/CardDavBackend.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -897,14 +897,16 @@ public function getChangesForAddressBook($addressBookId, $syncToken, $syncLevel,
897897
->setMaxResults($limit);
898898
$stmt = $qb->executeQuery();
899899
$values = $stmt->fetchAll(\PDO::FETCH_ASSOC);
900-
$lastID = end($values)['id'];
901-
$result['syncToken'] = 'init_' . $lastID . '_' . $initialSyncToken;
902-
$result['added'] = array_column($values, 'uri');
903900
$stmt->closeCursor();
904-
$result['result_truncated'] = true;
905-
if (count($result['added']) < $limit) {
901+
if (count($values) === 0) {
906902
$result['syncToken'] = $initialSyncToken;
907903
$result['result_truncated'] = false;
904+
$result['added'] = [];
905+
} else {
906+
$lastID = end($values)['id'];
907+
$result['added'] = array_column($values, 'uri');
908+
$result['syncToken'] = count($result['added']) === $limit ? "init_{$lastID}_$initialSyncToken" : $initialSyncToken ;
909+
$result['result_truncated'] = count($result['added']) === $limit;
908910
}
909911
} elseif ($syncToken) {
910912
$qb = $this->db->getQueryBuilder();

apps/federation/lib/SyncFederationAddressBooks.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function syncThemAll(\Closure $callback) {
5252
try {
5353
$newToken = $this->syncService->syncRemoteAddressBook($url, $cardDavUser, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties);
5454
if ($newToken !== $syncToken) {
55+
// Finish truncated initial sync.
5556
if (strpos($newToken, 'init') !== false) {
5657
$newToken = $this->syncTruncatedAddressBook($url, $cardDavUser, $addressBookUrl, $sharedSecret, $newToken, $targetBookId, $targetPrincipal, $targetBookProperties);
5758
}
@@ -82,7 +83,7 @@ public function syncThemAll(\Closure $callback) {
8283

8384
private function syncTruncatedAddressBook(string $url, string $cardDavUser, string $addressBookUrl, string $sharedSecret, string $syncToken, int $targetBookId, string $targetPrincipal, array $targetBookProperties): string {
8485
$newToken = $this->syncService->syncRemoteAddressBook($url, $cardDavUser, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties);
85-
while(strpos($newToken, 'init') !== false) {
86+
while (strpos($newToken, 'init') !== false) {
8687
$newToken = $this->syncService->syncRemoteAddressBook($url, $cardDavUser, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties);
8788
}
8889
return $newToken;

0 commit comments

Comments
 (0)