Fixed master slave configuration

The setup of ConnectionManagerMasterSlave was basically broken since
connection->slave node does not provide all necessary information
to be able to setup a valid connection link. Also Symfony's default
database_driver parameter which includes pdo_ as prefix was not correctly
converted/renamed for those slaves
This commit is contained in:
Marc J. Schmidt 2015-03-12 18:02:40 +01:00
parent f34a6d28f7
commit c6e7355f7a
2 changed files with 19 additions and 5 deletions

View file

@ -129,7 +129,7 @@ class Configuration extends PropelConfiguration
->cannotBeEmpty()
->beforeNormalization()
->ifString()
->then(function ($v) { return str_replace('pdo_', '', strtolower($v)); })
->then(function ($v) { return preg_replace('/^pdo_/', '', strtolower($v)); })
->end()
->validate()
->ifNotInArray($validAdapters)
@ -141,7 +141,7 @@ class Configuration extends PropelConfiguration
->cannotBeEmpty()
->beforeNormalization()
->ifString()
->then(function ($v) { return str_replace('pdo_', '', $v); })
->then(function ($v) { return preg_replace('/^pdo_/', '', $v); })
->end()
->end()
->scalarNode('user')->isRequired()->end()
@ -170,7 +170,12 @@ class Configuration extends PropelConfiguration
->arrayNode('slaves')
->prototype('array')
->children()
->scalarNode('dsn')->end()
->scalarNode('dsn')
->beforeNormalization()
->ifString()
->then(function ($v) { return preg_replace('/^pdo_/', '', $v); })
->end()
->end()
->end()
->end()
->end()

View file

@ -64,9 +64,18 @@ class PropelBundle extends Bundle
$manager = new ConnectionManagerMasterSlave();
// configure the master (write) connection
$manager->setWriteConfiguration($config['connection']);
$manager->setWriteConfiguration($config);
// configure the slave (read) connections
$manager->setReadConfiguration($config['slaves']);
$slaveConnections = [];
foreach ($config['slaves'] as $slave) {
$slaveConnections[] = array_merge($config, [
'dsn' => $slave['dsn'],
'slaves' => null
]);
}
$manager->setReadConfiguration($slaveConnections);
} else {
$manager = new ConnectionManagerSingle();
$manager->setConfiguration($config);