aboutsummaryrefslogtreecommitdiffstats
path: root/apps/federation/lib/SyncFederationAddressBooks.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/federation/lib/SyncFederationAddressBooks.php')
-rw-r--r--apps/federation/lib/SyncFederationAddressBooks.php42
1 files changed, 28 insertions, 14 deletions
diff --git a/apps/federation/lib/SyncFederationAddressBooks.php b/apps/federation/lib/SyncFederationAddressBooks.php
index 46a6a8c40a5..d11f92b76ef 100644
--- a/apps/federation/lib/SyncFederationAddressBooks.php
+++ b/apps/federation/lib/SyncFederationAddressBooks.php
@@ -14,20 +14,15 @@ use OCP\OCS\IDiscoveryService;
use Psr\Log\LoggerInterface;
class SyncFederationAddressBooks {
- protected DbHandler $dbHandler;
- private SyncService $syncService;
private DiscoveryService $ocsDiscoveryService;
- private LoggerInterface $logger;
- public function __construct(DbHandler $dbHandler,
- SyncService $syncService,
+ public function __construct(
+ protected DbHandler $dbHandler,
+ private SyncService $syncService,
IDiscoveryService $ocsDiscoveryService,
- LoggerInterface $logger
+ private LoggerInterface $logger,
) {
- $this->syncService = $syncService;
- $this->dbHandler = $dbHandler;
$this->ocsDiscoveryService = $ocsDiscoveryService;
- $this->logger = $logger;
}
/**
@@ -39,7 +34,7 @@ class SyncFederationAddressBooks {
$url = $trustedServer['url'];
$callback($url, null);
$sharedSecret = $trustedServer['shared_secret'];
- $syncToken = $trustedServer['sync_token'];
+ $oldSyncToken = $trustedServer['sync_token'];
$endPoints = $this->ocsDiscoveryService->discover($url, 'FEDERATED_SHARING');
$cardDavUser = $endPoints['carddav-user'] ?? 'system';
@@ -50,16 +45,35 @@ class SyncFederationAddressBooks {
continue;
}
$targetBookId = $trustedServer['url_hash'];
- $targetPrincipal = "principals/system/system";
+ $targetPrincipal = 'principals/system/system';
$targetBookProperties = [
'{DAV:}displayname' => $url
];
+
try {
- $newToken = $this->syncService->syncRemoteAddressBook($url, $cardDavUser, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties);
- if ($newToken !== $syncToken) {
- $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $newToken);
+ $syncToken = $oldSyncToken;
+
+ do {
+ [$syncToken, $truncated] = $this->syncService->syncRemoteAddressBook(
+ $url,
+ $cardDavUser,
+ $addressBookUrl,
+ $sharedSecret,
+ $syncToken,
+ $targetBookId,
+ $targetPrincipal,
+ $targetBookProperties
+ );
+ } while ($truncated);
+
+ if ($syncToken !== $oldSyncToken) {
+ $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $syncToken);
} else {
$this->logger->debug("Sync Token for $url unchanged from previous sync");
+ // The server status might have been changed to a failure status in previous runs.
+ if ($this->dbHandler->getServerStatus($url) !== TrustedServers::STATUS_OK) {
+ $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK);
+ }
}
} catch (\Exception $ex) {
if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) {