Skip to content

Commit

Permalink
make it mandatory to enable savepoints for nested transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
dmaicher committed Jun 8, 2023
1 parent 2048cc7 commit e6840ba
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ private function modifyConnectionService(ContainerBuilder $container, string $na
{
$connectionDefinition = $container->getDefinition(sprintf('doctrine.dbal.%s_connection', $name));

if (!$this->hasSavepointsEnabled($connectionDefinition)) {
throw new \LogicException(sprintf('This bundle relies on savepoints for nested database transactions. You need to enable "use_savepoints" on the Doctrine DBAL config for connection "%s".', $name));
}

$connectionDefinition->replaceArgument(
0,
$this->getModifiedConnectionOptions($connectionDefinition->getArgument(0), $name),
Expand Down Expand Up @@ -174,4 +178,15 @@ private function validateConnectionNames(array $configNames, array $existingName
throw new \InvalidArgumentException(sprintf('Unknown doctrine dbal connection name(s): %s.', implode(', ', $unknown)));
}
}

private function hasSavepointsEnabled(Definition $connectionDefinition): bool
{
foreach ($connectionDefinition->getMethodCalls() as $call) {
if ($call[0] === 'setNestTransactionsWithSavepoints' && $call[1]) {
return true;
}
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public function testProcess(array $config, callable $assertCallback, callable $e
],
]]));

foreach (['a', 'b', 'c'] as $name) {
$containerBuilder->getDefinition(sprintf('doctrine.dbal.%s_connection', $name))
->addMethodCall('setNestTransactionsWithSavepoints', [true])
;
}

$containerBuilder->setDefinition(
'doctrine.dbal.a_connection.configuration',
(new Definition(Configuration::class))
Expand Down

0 comments on commit e6840ba

Please sign in to comment.