Skip to content

Commit fcdbbf5

Browse files
bwaidelichmhsdesign
authored andcommitted
Use dedicated connection for EventStore
in order to prevent nested transactions potentially leading to RuntimeException of A transaction is active already, can't commit events!
1 parent 35ad74a commit fcdbbf5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Neos.ContentRepositoryRegistry/Classes/Factory/EventStore/DoctrineEventStoreFactory.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
namespace Neos\ContentRepositoryRegistry\Factory\EventStore;
55

6-
use Doctrine\DBAL\Connection;
6+
use Doctrine\DBAL\DriverManager;
7+
use Doctrine\ORM\EntityManagerInterface;
78
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
89
use Neos\EventStore\DoctrineAdapter\DoctrineEventStore;
910
use Neos\EventStore\EventStoreInterface;
@@ -12,15 +13,17 @@
1213
class DoctrineEventStoreFactory implements EventStoreFactoryInterface
1314
{
1415
public function __construct(
15-
private readonly Connection $connection,
16+
private readonly EntityManagerInterface $entityManager,
1617
) {
1718
}
1819

1920
/** @param array<string, mixed> $options */
2021
public function build(ContentRepositoryId $contentRepositoryId, array $options, ClockInterface $clock): EventStoreInterface
2122
{
23+
// We create a new connection instance in order to avoid nested transactions
24+
$connection = DriverManager::getConnection($this->entityManager->getConnection()->getParams(), $this->entityManager->getConfiguration(), $this->entityManager->getEventManager());
2225
return new DoctrineEventStore(
23-
$this->connection,
26+
$connection,
2427
self::databaseTableName($contentRepositoryId),
2528
$clock
2629
);

0 commit comments

Comments
 (0)