Skip to content

Commit 5bb1097

Browse files
committed
Enabling several tdbm lock files when multiple dbs are used
1 parent 411e1cc commit 5bb1097

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
/.phpunit.result.cache
77
/var
88
/tdbm*.lock.yml
9+
/phpunit.xml

DependencyInjection/TdbmExtension.php

+20-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
use TheCodingMachine\TDBM\Utils\DefaultNamingStrategy;
2222
use TheCodingMachine\TDBM\Utils\NamingStrategyInterface;
2323
use TheCodingMachine\TDBM\SchemaLockFileDumper;
24+
use TheCodingMachine\TDBM\Utils\RootProjectLocator;
25+
use function strlen;
26+
use function substr;
2427

2528
class TdbmExtension extends Extension
2629
{
@@ -66,7 +69,7 @@ private function nD(string $class = null, array $arguments = []): Definition
6669
$definition->setAutowired(true);
6770
$definition->setAutoconfigured(true);
6871
$definition->setPublic(false);
69-
72+
7073
return $definition;
7174
}
7275

@@ -104,6 +107,22 @@ private function getConfigurationDefinition(ConnectionConfiguration $config, str
104107
$configuration->setArgument('$namingStrategy', new Reference($namingStrategyServiceId));
105108
$configuration->setArgument('$codeGeneratorListeners', [new Reference(SymfonyCodeGeneratorListener::class)]);
106109
$configuration->setArgument('$cache', new Reference('tdbm.cache'));
110+
111+
// Let's name the tdbm lock file after the name of the DBAL connection.
112+
113+
// A DBAL connection is in the form: "doctrine.dbal.default_connection"
114+
$connectionName = $config->getConnection();
115+
if (strpos($connectionName, 'doctrine.dbal.') === 0) {
116+
$connectionName = substr($connectionName, 14);
117+
if (strpos($connectionName, '_connection') === strlen($connectionName) - 11) {
118+
$connectionName = substr($connectionName, 0, strlen($connectionName) - 11);
119+
}
120+
}
121+
122+
if ($connectionName !== 'default') {
123+
$configuration->setArgument('$lockFilePath', RootProjectLocator::getRootLocationPath().'tdbm.'.$connectionName.'.lock.yml');
124+
}
125+
107126
return $configuration;
108127
}
109128

0 commit comments

Comments
 (0)