From af29f388dab44a8409fb548c2b17dc7a31dbbe71 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 19 Sep 2022 20:34:42 +0200 Subject: [PATCH] [ticket/17010] Queue notifications and use flush to send them PHPBB3-17010 --- phpBB/phpbb/notification/method/webpush.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/notification/method/webpush.php b/phpBB/phpbb/notification/method/webpush.php index 0fc704e8de..550631ec77 100644 --- a/phpBB/phpbb/notification/method/webpush.php +++ b/phpBB/phpbb/notification/method/webpush.php @@ -185,6 +185,7 @@ class webpush extends \phpbb\notification\method\messenger_base $web_push = new \Minishlink\WebPush\WebPush($auth); + $number_of_notifications = 0; // Time to go through the queue and send emails /** @var type_interface $notification */ foreach ($this->queue as $notification) @@ -222,9 +223,8 @@ class webpush extends \phpbb\notification\method\messenger_base ], 'contentEncoding' => !empty($subscription['encoding']) ? $subscription['encoding'] : null, ]); - //$web_push->queueNotification($push_subscription, $json_data); - $foo = $web_push->sendOneNotification($push_subscription, $json_data); - $meh = 2; + $web_push->queueNotification($push_subscription, $json_data); + $number_of_notifications++; } catch (\ErrorException $exception) { @@ -235,6 +235,21 @@ class webpush extends \phpbb\notification\method\messenger_base } // @todo: Try offloading to after request + try + { + foreach ($web_push->flush($number_of_notifications) as $report) + { + if (!$report->isSuccess()) + { + // @todo: log errors / remove subscription + } + } + } + catch (\ErrorException $exception) + { + // @todo: write to log + } + // We're done, empty the queue $this->empty_queue();