Skip to content

Commit

Permalink
Make master connections respect driverOptions (#1253)
Browse files Browse the repository at this point in the history
Changes introduced in 4353686 fixed the problem for creating and dropping commands, but introduced issues everywhere else where primary/replica options are used. This patch reverts back previous handling and patches only individual commands that manipulate with connection options.
  • Loading branch information
petewalker authored Nov 10, 2020
1 parent 5226200 commit 5a94ec5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
14 changes: 11 additions & 3 deletions Command/CreateDatabaseDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,22 @@ protected function execute(InputInterface $input, OutputInterface $output)

$ifNotExists = $input->getOption('if-not-exists');

$params = $connection->getParams();
$driverOptions = [];
$params = $connection->getParams();

if (isset($params['driverOptions'])) {
$driverOptions = $params['driverOptions'];
}

if (isset($params['master'])) {
$params = $params['master'];
$params = $params['master'];
$params['driverOptions'] = $driverOptions;
}

// Since doctrine/dbal 2.11 master has been replaced by primary
if (isset($params['primary'])) {
$params = $params['primary'];
$params = $params['primary'];
$params['driverOptions'] = $driverOptions;
}

// Cannot inject `shard` option in parent::getDoctrineConnection
Expand Down
14 changes: 11 additions & 3 deletions Command/DropDatabaseDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,22 @@ protected function execute(InputInterface $input, OutputInterface $output)

$ifExists = $input->getOption('if-exists');

$params = $connection->getParams();
$driverOptions = [];
$params = $connection->getParams();

if (isset($params['driverOptions'])) {
$driverOptions = $params['driverOptions'];
}

if (isset($params['master'])) {
$params = $params['master'];
$params = $params['master'];
$params['driverOptions'] = $driverOptions;
}

// Since doctrine/dbal 2.11 master has been replaced by primary
if (isset($params['primary'])) {
$params = $params['primary'];
$params = $params['primary'];
$params['driverOptions'] = $driverOptions;
}

if (isset($params['shards'])) {
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ protected function getConnectionOptions($connection)
if (! empty($options['slaves'])) {
$nonRewrittenKeys = [
'driver' => true,
'driverOptions' => true,
'driverClass' => true,
'wrapperClass' => true,
'keepSlave' => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ public function testDbalLoadSingleMasterSlaveConnection()
'dbname' => 'mysql_db',
'host' => 'localhost',
'unix_socket' => '/path/to/mysqld.sock',
'driverOptions' => [],
],
$param['master']
);
Expand Down

0 comments on commit 5a94ec5

Please sign in to comment.