diff options
author | Joas Schilling <coding@schilljs.com> | 2022-02-24 12:46:49 +0300 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2022-02-25 22:57:37 +0300 |
commit | 009cbe2194a28a015185d4636288dc1c40078a97 (patch) | |
tree | 4fc92c205144e1d98778b4431fa6fe825cbf94d5 | |
parent | a365b49ee47ab5575e32ac811f3f244d52fddd89 (diff) |
Wrap notification generation in a transactionbackport/6929/stable23
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | lib/Notification/Listener.php | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/lib/Notification/Listener.php b/lib/Notification/Listener.php index 2919329e6..fa62ff721 100644 --- a/lib/Notification/Listener.php +++ b/lib/Notification/Listener.php @@ -31,6 +31,7 @@ use OCA\Talk\Room; use OCA\Talk\Service\ParticipantService; use OCP\AppFramework\Utility\ITimeFactory; use OCP\EventDispatcher\IEventDispatcher; +use OCP\IDBConnection; use OCP\Notification\IManager; use OCP\IUser; use OCP\IUserSession; @@ -38,6 +39,8 @@ use Psr\Log\LoggerInterface; class Listener { + /** @var IDBConnection */ + protected $connection; /** @var IManager */ protected $notificationManager; /** @var ParticipantService */ @@ -54,12 +57,14 @@ class Listener { /** @var bool */ protected $shouldSendCallNotification = false; - public function __construct(IManager $notificationManager, + public function __construct(IDBConnection $connection, + IManager $notificationManager, ParticipantService $participantsService, IEventDispatcher $dispatcher, IUserSession $userSession, ITimeFactory $timeFactory, LoggerInterface $logger) { + $this->connection = $connection; $this->notificationManager = $notificationManager; $this->participantsService = $participantsService; $this->dispatcher = $dispatcher; @@ -248,18 +253,25 @@ class Listener { } $userIds = $this->participantsService->getParticipantUserIdsForCallNotifications($room); - foreach ($userIds as $userId) { - if ($actorId === $userId) { - continue; - } - - try { - $notification->setUser($userId); - $this->notificationManager->notify($notification); - } catch (\InvalidArgumentException $e) { - $this->logger->error($e->getMessage(), ['exception' => $e]); + $this->connection->beginTransaction(); + try { + foreach ($userIds as $userId) { + if ($actorId === $userId) { + continue; + } + + try { + $notification->setUser($userId); + $this->notificationManager->notify($notification); + } catch (\InvalidArgumentException $e) { + $this->logger->error($e->getMessage(), ['exception' => $e]); + } } + } catch (\Throwable $e) { + $this->connection->rollBack(); + throw $e; } + $this->connection->commit(); if ($shouldFlush) { $this->notificationManager->flush(); |