Skip to content

Commit

Permalink
Add --default option to database:add (#4143)
Browse files Browse the repository at this point in the history
This option allows to set the database as the default one instead of
adding a new database in addition to the default one.

See: #4142
  • Loading branch information
Kwadz authored and enzolutions committed Sep 6, 2019
1 parent 3c83f02 commit c4a3b5f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Command/Database/AddCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ protected function configure()
InputOption::VALUE_OPTIONAL,
$this->trans('commands.database.add.options.driver')
)
->addOption(
'default',
null,
InputOption::VALUE_NONE,
$this->trans('commands.database.query.options.default')
)
->setHelp($this->trans('commands.database.add.help'))
->setAliases(['dba']);
}
Expand Down
6 changes: 5 additions & 1 deletion src/Generator/DatabaseSettingsGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ public function generate(array $parameters)
if (!is_writable($settingsFile)) {
return false;
}
$template = 'database/add.php.twig';
if ($parameters['default']) {
$template = 'database/add-default.php.twig';
}
return $this->renderFile(
'database/add.php.twig',
$template,
$settingsFile,
$parameters,
FILE_APPEND
Expand Down
10 changes: 10 additions & 0 deletions templates/database/add-default.php.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

$databases['default']['default'] = [
'database' => '{{ database }}',
'username' => '{{ username }}',
'password' => '{{ password }}',
'host' => '{{ host }}',
'port' => '{{ port }}',
'driver' => '{{ driver }}',
'prefix' => '{{ prefix }}',
];

0 comments on commit c4a3b5f

Please sign in to comment.