From 967c7a5fe926142b4b458e0f422f8d19bd98cf16 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 22 Jun 2018 10:47:18 +0200 Subject: [PATCH 1/8] fixed comment --- Command/CreateDatabaseDoctrineCommand.php | 2 +- Command/DropDatabaseDoctrineCommand.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Command/CreateDatabaseDoctrineCommand.php b/Command/CreateDatabaseDoctrineCommand.php index d5de6f764..4b2bfdb1a 100644 --- a/Command/CreateDatabaseDoctrineCommand.php +++ b/Command/CreateDatabaseDoctrineCommand.php @@ -8,7 +8,7 @@ use Symfony\Component\Console\Output\OutputInterface; /** - * Database tool allows you to easily drop and create your configured databases. + * Database tool allows you to easily create your configured databases. */ class CreateDatabaseDoctrineCommand extends DoctrineCommand { diff --git a/Command/DropDatabaseDoctrineCommand.php b/Command/DropDatabaseDoctrineCommand.php index 8c257b78d..320f83978 100644 --- a/Command/DropDatabaseDoctrineCommand.php +++ b/Command/DropDatabaseDoctrineCommand.php @@ -8,7 +8,7 @@ use Symfony\Component\Console\Output\OutputInterface; /** - * Database tool allows you to easily drop and create your configured databases. + * Database tool allows you to easily drop your configured databases. */ class DropDatabaseDoctrineCommand extends DoctrineCommand { From e0f759943dccf65176d1b37a3fc9318cc9ceae26 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 22 Jun 2018 10:47:35 +0200 Subject: [PATCH 2/8] use same order of options like in CreateDatabaseDoctrineCommand --- Command/DropDatabaseDoctrineCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Command/DropDatabaseDoctrineCommand.php b/Command/DropDatabaseDoctrineCommand.php index 320f83978..1a8838dd1 100644 --- a/Command/DropDatabaseDoctrineCommand.php +++ b/Command/DropDatabaseDoctrineCommand.php @@ -24,8 +24,8 @@ protected function configure() $this ->setName('doctrine:database:drop') ->setDescription('Drops the configured database') - ->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'The connection to use for this command') ->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command') + ->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'The connection to use for this command') ->addOption('if-exists', null, InputOption::VALUE_NONE, 'Don\'t trigger an error, when the database doesn\'t exist') ->addOption('force', null, InputOption::VALUE_NONE, 'Set this parameter to execute this action') ->setHelp(<< Date: Fri, 22 Jun 2018 10:48:28 +0200 Subject: [PATCH 3/8] use the same approach to get the connection name like in CreateDoctrineDatabaseCommand --- Command/DropDatabaseDoctrineCommand.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Command/DropDatabaseDoctrineCommand.php b/Command/DropDatabaseDoctrineCommand.php index 1a8838dd1..5d53ec2de 100644 --- a/Command/DropDatabaseDoctrineCommand.php +++ b/Command/DropDatabaseDoctrineCommand.php @@ -49,7 +49,12 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $connection = $this->getDoctrineConnection($input->getOption('connection')); + $connectionName = $input->getOption('connection'); + if (empty($connectionName) === true) { + $connectionName = $this->getContainer()->get('doctrine')->getDefaultConnectionName(); + } + $connection = $this->getDoctrineConnection($connectionName); + $ifExists = $input->getOption('if-exists'); $params = $connection->getParams(); From 466e76fa63168f9ac2e22342f7d49d4e40cb2a37 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 22 Jun 2018 10:49:15 +0200 Subject: [PATCH 4/8] output the used connection name --- Command/DropDatabaseDoctrineCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Command/DropDatabaseDoctrineCommand.php b/Command/DropDatabaseDoctrineCommand.php index 5d53ec2de..eec14ce5c 100644 --- a/Command/DropDatabaseDoctrineCommand.php +++ b/Command/DropDatabaseDoctrineCommand.php @@ -87,7 +87,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if (! $input->getOption('force')) { $output->writeln('ATTENTION: This operation should not be executed in a production environment.'); $output->writeln(''); - $output->writeln(sprintf('Would drop the database named %s.', $name)); + $output->writeln(sprintf('Would drop the database %s for connection named %s.', $name, $connectionName)); $output->writeln('Please run the operation with --force to execute'); $output->writeln('All data will be lost!'); From f3004d664207e0e11060cec7684c0b1c7bfa9d4f Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 22 Jun 2018 10:49:29 +0200 Subject: [PATCH 5/8] fixed wrong output before not output of the dropped database name was given, only the connection name. --- Command/DropDatabaseDoctrineCommand.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Command/DropDatabaseDoctrineCommand.php b/Command/DropDatabaseDoctrineCommand.php index eec14ce5c..8482d5193 100644 --- a/Command/DropDatabaseDoctrineCommand.php +++ b/Command/DropDatabaseDoctrineCommand.php @@ -108,12 +108,12 @@ protected function execute(InputInterface $input, OutputInterface $output) try { if ($shouldDropDatabase) { $connection->getSchemaManager()->dropDatabase($name); - $output->writeln(sprintf('Dropped database for connection named %s', $name)); + $output->writeln(sprintf('Dropped database %s for connection named %s', $name, $connectionName)); } else { - $output->writeln(sprintf('Database for connection named %s doesn\'t exist. Skipped.', $name)); + $output->writeln(sprintf('Database %s for connection named %s doesn\'t exist. Skipped.', $name, $connectionName)); } } catch (\Exception $e) { - $output->writeln(sprintf('Could not drop database for connection named %s', $name)); + $output->writeln(sprintf('Could not drop database %s for connection named %s', $name, $connectionName)); $output->writeln(sprintf('%s', $e->getMessage())); return self::RETURN_CODE_NOT_DROP; From e9a7c5f278cb37c1a6c4bde7b29da6cfd307814d Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 22 Jun 2018 10:53:51 +0200 Subject: [PATCH 6/8] fixed tests --- Tests/Command/DropDatabaseDoctrineTest.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Tests/Command/DropDatabaseDoctrineTest.php b/Tests/Command/DropDatabaseDoctrineTest.php index 699f90bee..c7f1d4674 100644 --- a/Tests/Command/DropDatabaseDoctrineTest.php +++ b/Tests/Command/DropDatabaseDoctrineTest.php @@ -30,7 +30,14 @@ public function testExecute() array_merge(['command' => $command->getName(), '--force' => true]) ); - $this->assertContains('Dropped database for connection named ' . sys_get_temp_dir() . '/' . $dbName . '', $commandTester->getDisplay()); + $this->assertContains( + sprintf( + 'Dropped database %s for connection named %s', + sys_get_temp_dir() . '/' . $dbName, + $connectionName + ), + $commandTester->getDisplay() + ); } public function testExecuteWithoutOptionForceWillFailWithAttentionMessage() @@ -53,7 +60,14 @@ public function testExecuteWithoutOptionForceWillFailWithAttentionMessage() array_merge(['command' => $command->getName()]) ); - $this->assertContains('Would drop the database named ' . sys_get_temp_dir() . '/' . $dbName . '.', $commandTester->getDisplay()); + $this->assertContains( + sprintf( + 'Would drop the database %s for connection named %s.', + sys_get_temp_dir() . '/' . $dbName, + $connectionName + ), + $commandTester->getDisplay() + ); $this->assertContains('Please run the operation with --force to execute', $commandTester->getDisplay()); } From b80f138eaf20c6aefb8e5369e5fb4d37eff39766 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 22 Jun 2018 11:58:37 +0200 Subject: [PATCH 7/8] do not compare bool again --- Command/CreateDatabaseDoctrineCommand.php | 2 +- Command/DropDatabaseDoctrineCommand.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Command/CreateDatabaseDoctrineCommand.php b/Command/CreateDatabaseDoctrineCommand.php index 4b2bfdb1a..4401942a1 100644 --- a/Command/CreateDatabaseDoctrineCommand.php +++ b/Command/CreateDatabaseDoctrineCommand.php @@ -41,7 +41,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $connectionName = $input->getOption('connection'); - if (empty($connectionName) === true) { + if (empty($connectionName)) { $connectionName = $this->getContainer()->get('doctrine')->getDefaultConnectionName(); } $connection = $this->getDoctrineConnection($connectionName); diff --git a/Command/DropDatabaseDoctrineCommand.php b/Command/DropDatabaseDoctrineCommand.php index 8482d5193..2f76e6b59 100644 --- a/Command/DropDatabaseDoctrineCommand.php +++ b/Command/DropDatabaseDoctrineCommand.php @@ -50,7 +50,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $connectionName = $input->getOption('connection'); - if (empty($connectionName) === true) { + if (empty($connectionName)) { $connectionName = $this->getContainer()->get('doctrine')->getDefaultConnectionName(); } $connection = $this->getDoctrineConnection($connectionName); From 60dd14b6c031439d50560c0850f650d85346202c Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 22 Jun 2018 11:59:50 +0200 Subject: [PATCH 8/8] CS fix --- Command/DropDatabaseDoctrineCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Command/DropDatabaseDoctrineCommand.php b/Command/DropDatabaseDoctrineCommand.php index 2f76e6b59..42974d075 100644 --- a/Command/DropDatabaseDoctrineCommand.php +++ b/Command/DropDatabaseDoctrineCommand.php @@ -55,7 +55,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } $connection = $this->getDoctrineConnection($connectionName); - $ifExists = $input->getOption('if-exists'); + $ifExists = $input->getOption('if-exists'); $params = $connection->getParams(); if (isset($params['master'])) {