diff --git a/lib/Controller/SignalingController.php b/lib/Controller/SignalingController.php index d2e8a9f22bf..a92e60745c8 100644 --- a/lib/Controller/SignalingController.php +++ b/lib/Controller/SignalingController.php @@ -25,7 +25,6 @@ namespace OCA\Talk\Controller; -use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use OCA\Talk\Config; use OCA\Talk\Events\SignalingEvent; use OCA\Talk\Exceptions\RoomNotFoundException; @@ -43,6 +42,7 @@ use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCSController; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\DB\Exception; use OCP\EventDispatcher\IEventDispatcher; use OCP\Http\Client\IClientService; use OCP\IDBConnection; @@ -647,7 +647,7 @@ private function backendRoom(array $roomRequest): DataResponse { if ($sessionId && !$participant->getSession() instanceof Session) { try { $session = $this->sessionService->createSessionForAttendee($participant->getAttendee(), $sessionId); - } catch (UniqueConstraintViolationException $e) { + } catch (Exception $e) { return new DataResponse([ 'type' => 'error', 'error' => [ diff --git a/lib/Service/SessionService.php b/lib/Service/SessionService.php index 4b4f6e6c0fa..6dbf1e3fbb9 100644 --- a/lib/Service/SessionService.php +++ b/lib/Service/SessionService.php @@ -23,10 +23,10 @@ namespace OCA\Talk\Service; -use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use OCA\Talk\Model\Attendee; use OCA\Talk\Model\Session; use OCA\Talk\Model\SessionMapper; +use OCP\DB\Exception; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; use OCP\Security\ISecureRandom; @@ -90,7 +90,7 @@ public function getAllSessionsForAttendee(Attendee $attendee): array { * @param Attendee $attendee * @param string $forceSessionId * @return Session - * @throws UniqueConstraintViolationException + * @throws Exception */ public function createSessionForAttendee(Attendee $attendee, string $forceSessionId = ''): Session { $session = new Session(); @@ -98,12 +98,7 @@ public function createSessionForAttendee(Attendee $attendee, string $forceSessio if ($forceSessionId !== '') { $session->setSessionId($forceSessionId); - try { - $this->sessionMapper->insert($session); - } catch (UniqueConstraintViolationException $e) { - // The HPB told us to use a session which exists already… - throw $e; - } + $this->sessionMapper->insert($session); } else { while (true) { $sessionId = $this->secureRandom->generate(255); @@ -111,8 +106,11 @@ public function createSessionForAttendee(Attendee $attendee, string $forceSessio try { $this->sessionMapper->insert($session); break; - } catch (UniqueConstraintViolationException $e) { + } catch (Exception $e) { // 255 chars are not unique? Try again... + if ($e->getReason() === Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) { + throw $e; + } } } }