Skip to content

Commit

Permalink
fixup! feat(cardav): support result truncation for addressbook federa…
Browse files Browse the repository at this point in the history
…tion

Signed-off-by: Hamza Mahjoubi <[email protected]>
  • Loading branch information
hamza221 authored and AndyScherzinger committed Feb 5, 2025
1 parent eaad0d0 commit 2e2983a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 7 additions & 5 deletions apps/dav/lib/CardDAV/CardDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion apps/federation/lib/SyncFederationAddressBooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check failure on line 57 in apps/federation/lib/SyncFederationAddressBooks.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidScalarArgument

apps/federation/lib/SyncFederationAddressBooks.php:57:114: InvalidScalarArgument: Argument 6 of OCA\Federation\SyncFederationAddressBooks::syncTruncatedAddressBook expects int, but string provided (see https://psalm.dev/012)
}
Expand Down Expand Up @@ -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);

Check failure on line 85 in apps/federation/lib/SyncFederationAddressBooks.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidScalarArgument

apps/federation/lib/SyncFederationAddressBooks.php:85:121: InvalidScalarArgument: Argument 6 of OCA\DAV\CardDAV\SyncService::syncRemoteAddressBook expects string, but int provided (see https://psalm.dev/012)
while(strpos($newToken, 'init') !== false) {
while (strpos($newToken, 'init') !== false) {
$newToken = $this->syncService->syncRemoteAddressBook($url, $cardDavUser, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties);

Check failure on line 87 in apps/federation/lib/SyncFederationAddressBooks.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidScalarArgument

apps/federation/lib/SyncFederationAddressBooks.php:87:122: InvalidScalarArgument: Argument 6 of OCA\DAV\CardDAV\SyncService::syncRemoteAddressBook expects string, but int provided (see https://psalm.dev/012)
}
return $newToken;
Expand Down

0 comments on commit 2e2983a

Please sign in to comment.