Skip to content

Commit

Permalink
3978 db dump exception (#3979)
Browse files Browse the repository at this point in the history
* Add new arguments key and target. Make it possible use not only default target for db connections

* Throw an exception if db is not found
  • Loading branch information
LOBsTerr committed Apr 10, 2019
1 parent ad79269 commit 6d6ac03
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions src/Command/Shared/ConnectTrait.php
Expand Up @@ -16,31 +16,21 @@ trait ConnectTrait
public function resolveConnection($key = 'default', $target = 'default')
{
$connectionInfo = Database::getConnectionInfo($key);
if (!$connectionInfo || !isset($connectionInfo[$target])) {
$this->getIo()->error(
sprintf(
$this->trans('commands.database.connect.messages.database-not-found'),
$key,
$target
)
);

return null;
if (empty($connectionInfo[$target])) {
throw new \Exception(sprintf(
$this->trans('commands.database.connect.messages.database-not-found'),
$key,
$target
));
}

$databaseConnection = $connectionInfo[$target];
if (!in_array($databaseConnection['driver'], $this->supportedDrivers)) {
$this->getIo()->error(
sprintf(
$this->trans('commands.database.connect.messages.database-not-supported'),
$databaseConnection['driver']
)
);

return null;
else if (!in_array($connectionInfo[$target]['driver'], $this->supportedDrivers)) {
throw new \Exception(sprintf(
$this->trans('commands.database.connect.messages.database-not-supported'),
$connectionInfo[$target]['driver']
));
}

return $databaseConnection;
return $connectionInfo[$target];
}

public function getRedBeanConnection($database = 'default')
Expand Down

0 comments on commit 6d6ac03

Please sign in to comment.