diff --git a/lib/Db/EventWrapperRequest.php b/lib/Db/EventWrapperRequest.php index 1e4f4ee8e..967862438 100644 --- a/lib/Db/EventWrapperRequest.php +++ b/lib/Db/EventWrapperRequest.php @@ -11,8 +11,8 @@ namespace OCA\Circles\Db; +use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use OCA\Circles\Model\Federated\EventWrapper; -use OCP\DB\Exception; use Psr\Log\LoggerInterface; /** @@ -42,7 +42,7 @@ public function save(EventWrapper $wrapper): void { try { $qb->execute(); - } catch (Exception $e) { + } catch (UniqueConstraintViolationException $e) { $logger = \OCP\Server::get(LoggerInterface::class); $logger->warning('issue while storing event', ['exception' => $e]); } diff --git a/lib/Service/FederatedEventService.php b/lib/Service/FederatedEventService.php index 6ebc1eaea..9a6ed6771 100644 --- a/lib/Service/FederatedEventService.php +++ b/lib/Service/FederatedEventService.php @@ -396,9 +396,11 @@ public function initBroadcast(FederatedEvent $event): bool { $wrapper->setCreation(time()); $wrapper->setSeverity($event->getSeverity()); + $avoidDuplicate = []; if ($event->isAsync()) { $wrapper->setInstance($this->configService->getLoopbackInstance()); $this->eventWrapperRequest->save($wrapper); + $avoidDuplicate[] = $this->configService->getLoopbackInstance(); } foreach ($instances as $instance) { @@ -406,9 +408,15 @@ public function initBroadcast(FederatedEvent $event): bool { break; } + if (in_array($instance->getInstance(), $avoidDuplicate, true)) { + Server::get(\Psr\Log\LoggerInterface::class)->warning('duplicate instance, please verify the setup of Federated Teams', ['duplicate' => $avoidDuplicate, 'loopback' => $this->configService->getLoopbackInstance(), 'instance' => $instance->getInstance(), 'interface' => $instance->getInterface()]); + continue; + } + $wrapper->setInstance($instance->getInstance()); $wrapper->setInterface($instance->getInterface()); $this->eventWrapperRequest->save($wrapper); + $avoidDuplicate[] = $wrapper->getInstance(); } $request = new NCRequest('', Request::TYPE_POST);