Skip to content

Commit

Permalink
Add new arguments key and target. Make it possible use not only defau…
Browse files Browse the repository at this point in the history
…lt target for db connections (#3804)
  • Loading branch information
LOBsTerr authored and jmolivas committed Apr 22, 2018
1 parent 43db14f commit 1b95086
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
15 changes: 11 additions & 4 deletions src/Command/Database/ConnectCommand.php
Expand Up @@ -26,9 +26,15 @@ protected function configure()
->setName('database:connect')
->setDescription($this->trans('commands.database.connect.description'))
->addArgument(
'database',
'key',
InputArgument::OPTIONAL,
$this->trans('commands.database.connect.arguments.database'),
$this->trans('commands.database.connect.arguments.key'),
'default'
)
->addArgument(
'target',
InputArgument::OPTIONAL,
$this->trans('commands.database.connect.arguments.target'),
'default'
)
->setHelp($this->trans('commands.database.connect.help'))
Expand All @@ -40,8 +46,9 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$database = $input->getArgument('database');
$databaseConnection = $this->resolveConnection($database);
$key = $input->getArgument('key');
$target = $input->getArgument('target');
$databaseConnection = $this->resolveConnection($key, $target);

$connection = sprintf(
'%s -A --database=%s --user=%s --password=%s --host=%s --port=%s',
Expand Down
14 changes: 7 additions & 7 deletions src/Command/Shared/ConnectTrait.php
Expand Up @@ -11,24 +11,24 @@

trait ConnectTrait
{
protected $supportedDrivers = ['mysql','pgsql'];
protected $supportedDrivers = ['mysql', 'pgsql'];

public function resolveConnection($database = 'default')
public function resolveConnection($key = 'default', $target = 'default')
{
$connectionInfo = Database::getConnectionInfo();

if (!$connectionInfo || !isset($connectionInfo[$database])) {
$connectionInfo = Database::getConnectionInfo($key);
if (!$connectionInfo || !isset($connectionInfo[$target])) {
$this->getIo()->error(
sprintf(
$this->trans('commands.database.connect.messages.database-not-found'),
$database
$key,
$target
)
);

return null;
}

$databaseConnection = $connectionInfo[$database];
$databaseConnection = $connectionInfo[$target];
if (!in_array($databaseConnection['driver'], $this->supportedDrivers)) {
$this->getIo()->error(
sprintf(
Expand Down

0 comments on commit 1b95086

Please sign in to comment.