getPrincipaluri()); $calDavUser = $this->cloudIdManager->getCloudId($sharedWith, null)->getId(); $remoteUrl = $calendar->getRemoteUrl(); $syncToken = $calendar->getSyncTokenForSabre(); // Need to encode the cloud id as it might contain a colon which is not allowed in basic // auth according to RFC 7617 $calDavUser = base64_encode($calDavUser); $syncResponse = $this->syncService->syncRemoteCalendar( $remoteUrl, $calDavUser, $calendar->getToken(), $syncToken, $calendar, ); $newSyncToken = $syncResponse->getSyncToken(); // Check sync token format and extract the actual sync token integer $matches = []; if (!preg_match('/^http:\/\/sabre\.io\/ns\/sync\/([0-9]+)$/', $newSyncToken, $matches)) { $this->logger->error("Failed to sync federated calendar at $remoteUrl: New sync token has unexpected format: $newSyncToken", [ 'calendar' => $calendar->toCalendarInfo(), 'newSyncToken' => $newSyncToken, ]); return 0; } $newSyncToken = (int)$matches[1]; if ($newSyncToken !== $calendar->getSyncToken()) { $this->federatedCalendarMapper->updateSyncTokenAndTime( $calendar->getId(), $newSyncToken, ); } else { $this->logger->debug("Sync Token for $remoteUrl unchanged from previous sync"); $this->federatedCalendarMapper->updateSyncTime($calendar->getId()); } return $syncResponse->getDownloadedEvents(); } }