Skip to content

Commit

Permalink
Fix transaction handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusklocke committed Feb 5, 2024
1 parent 31bf744 commit 0c36045
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/Infrastructure/Persistence/ORM/DoctrineTransactionWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

use Doctrine\ORM\EntityManagerInterface;
use HexagonalPlayground\Application\OrmTransactionWrapperInterface;
use Throwable;

class DoctrineTransactionWrapper implements OrmTransactionWrapperInterface
{
Expand All @@ -22,20 +21,10 @@ public function __construct(EntityManagerInterface $entityManager)
*/
public function transactional(callable $callable)
{
$this->entityManager->beginTransaction();
$result = call_user_func($callable);

try {
$return = call_user_func($callable);
$this->entityManager->flush();

$this->entityManager->flush();
$this->entityManager->commit();

return $return;
} catch (Throwable $e) {
$this->entityManager->clear();
$this->entityManager->rollback();

throw $e;
}
return $result;
}
}
}

0 comments on commit 0c36045

Please sign in to comment.