Skip to content
Permalink
Browse files

Add new arguments key and target. Make it possible use not only defau…

…lt target for db connections (#3804)
  • Loading branch information...
LOBsTerr authored and jmolivas committed Apr 22, 2018
1 parent 43db14f commit 1b9508687741be4b92d0049fc900a906167aa781
Showing with 18 additions and 11 deletions.
  1. +11 −4 src/Command/Database/ConnectCommand.php
  2. +7 −7 src/Command/Shared/ConnectTrait.php
@@ -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'))
@@ -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',
@@ -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(

0 comments on commit 1b95086

Please sign in to comment.
You can’t perform that action at this time.