Conditions | 5 |
Paths | 20 |
Total Lines | 26 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
18 | protected function handleForManager(EntityManagerInterface $entityManager, Envelope $envelope, StackInterface $stack): Envelope |
||
19 | { |
||
20 | $entityManager->getConnection()->beginTransaction(); |
||
21 | |||
22 | $success = false; |
||
23 | try { |
||
24 | $envelope = $stack->next()->handle($envelope, $stack); |
||
25 | $entityManager->flush(); |
||
26 | $entityManager->getConnection()->commit(); |
||
27 | |||
28 | $success = true; |
||
29 | |||
30 | return $envelope; |
||
31 | } catch (\Throwable $exception) { |
||
32 | if ($exception instanceof HandlerFailedException) { |
||
33 | // Remove all HandledStamp from the envelope so the retry will execute all handlers again. |
||
34 | // When a handler fails, the queries of allegedly successful previous handlers just got rolled back. |
||
35 | throw new HandlerFailedException($exception->getEnvelope()->withoutAll(HandledStamp::class), $exception->getNestedExceptions()); |
||
36 | } |
||
37 | |||
38 | throw $exception; |
||
39 | } finally { |
||
40 | $connection = $entityManager->getConnection(); |
||
41 | |||
42 | if (! $success && $connection->isTransactionActive()) { |
||
43 | $connection->rollBack(); |
||
44 | } |
||
48 |