From 3551e6fc3855367233da6608bd7493cea2cbe6b1 Mon Sep 17 00:00:00 2001 From: Jonathan Treffler Date: Wed, 24 Jul 2024 14:19:24 +0200 Subject: [PATCH] fix web push transport getSubscriptionIdFromOptions --- lib/PushTransports/WebPushTransport.php | 9 +++++++-- lib/Transport/Transport.php | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/PushTransports/WebPushTransport.php b/lib/PushTransports/WebPushTransport.php index 6a8f3f4..ebd638a 100644 --- a/lib/PushTransports/WebPushTransport.php +++ b/lib/PushTransports/WebPushTransport.php @@ -28,6 +28,7 @@ namespace OCA\DavPush\PushTransports; use OCA\DavPush\Transport\Transport; use OCA\DavPush\Service\WebPushSubscriptionService; +use OCA\DavPush\Errors\WebPushSubscriptionNotFound; use Sabre\Xml\Service; @@ -96,10 +97,14 @@ class WebPushTransport extends Transport { $result = file_get_contents($data["pushResource"], false, $context); } - public function getSubscriptionIdFromOptions($options): int { + public function getSubscriptionIdFromOptions($options): ?int { ['pushResource' => $pushResource] = $this->parseOptions($options); - return $this->webPushSubscriptionService->findByPushResource($pushResource)->getSubscriptionId(); + try { + return $this->webPushSubscriptionService->findByPushResource($pushResource)->getSubscriptionId(); + } catch (WebPushSubscriptionNotFound $e) { + return null; + } } public function updateSubscription($subsciptionId, $options) { diff --git a/lib/Transport/Transport.php b/lib/Transport/Transport.php index 5e36c85..eb4bce8 100644 --- a/lib/Transport/Transport.php +++ b/lib/Transport/Transport.php @@ -62,7 +62,7 @@ abstract class Transport { // Transport needs to be able to map subscription options back to a subscription id. // API Requests to create and update a subscription are the same, therefore if a subscription id is associated with the given options the subscription is updated, otherwise a new subscription is added. // Which option(s) uniquely identify a subscription is implementation specific. - abstract public function getSubscriptionIdFromOptions($options): int; + abstract public function getSubscriptionIdFromOptions($options): ?int; // Change mutable options of the subscription (if any exist) abstract public function updateSubscription($subsciptionId, $options);