8000 [Messenger] Fix `DoctrineOpenTransactionLoggerMiddleware` by ro0NL · Pull Request #53487 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Messenger] Fix DoctrineOpenTransactionLoggerMiddleware #53487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[Messenger] Fix DoctrineOpenTransactionLoggerMiddleware
follow up #52075
  • Loading branch information
ro0NL authored Jan 10, 2024
commit c1e396c4d9bf8f9a478a3e6990f7945ea45ae935
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
class DoctrineOpenTransactionLoggerMiddleware extends AbstractDoctrineMiddleware
{
private $logger;
/** @var bool */
private $isHandling = false;
/** @var int */
private $currentTransactionLevel = 0;

public function __construct(ManagerRegistry $managerRegistry, string $entityManagerName = null, LoggerInterface $logger = null)
{
Expand All @@ -38,21 +38,19 @@ public function __construct(ManagerRegistry $managerRegistry, string $entityMana

protected function handleForManager(EntityManagerInterface $entityManager, Envelope $envelope, StackInterface $stack): Envelope
{
if ($this->isHandling) {
return $stack->next()->handle($envelope, $stack);
}

$this->isHandling = true;
$prevTransactionLevel = $this->currentTransactionLevel;
$this->currentTransactionLevel = $entityManager->getConnection()->getTransactionNestingLevel();

try {
return $stack->next()->handle($envelope, $stack);
} finally {
if ($entityManager->getConnection()->isTransactionActive()) {
if ($this->currentTransactionLevel !== $entityManager->getConnection()->getTransactionNestingLevel()) {
$this->logger->error('A handler opened a transaction but did not close it.', [
'message' => $envelope->getMessage(),
]);
}
$this->isHandling = false;

$this->currentTransactionLevel = $prevTransactionLevel;
}
}
}
0