From cdcb3f6b9ff9cec1223b46a636a8ecfe91d5aaad Mon Sep 17 00:00:00 2001 From: Maxim Date: Fri, 27 May 2016 23:07:47 +1000 Subject: [PATCH] Removed unnecessary catched exceptions in commands (#421) * Remove catch exception Because this is broken -vvv and don't show stack trace * Update DatabaseDropCommand.php * Update FixturesDumpCommand.php * Update TableDropCommand.php --- Command/DatabaseCreateCommand.php | 26 +++++-------- Command/DatabaseDropCommand.php | 14 ++----- Command/FixturesDumpCommand.php | 11 +----- Command/TableDropCommand.php | 62 ++++++++++++++----------------- 4 files changed, 40 insertions(+), 73 deletions(-) diff --git a/Command/DatabaseCreateCommand.php b/Command/DatabaseCreateCommand.php index ef06523..6c9f2af 100644 --- a/Command/DatabaseCreateCommand.php +++ b/Command/DatabaseCreateCommand.php @@ -54,27 +54,19 @@ class DatabaseCreateCommand extends AbstractCommand $query = 'CREATE DATABASE '. $dbName .';'; } - try { - $manager = new ConnectionManagerSingle(); - $manager->setConfiguration($this->getTemporaryConfiguration($config)); + $manager = new ConnectionManagerSingle(); + $manager->setConfiguration($this->getTemporaryConfiguration($config)); - $serviceContainer = Propel::getServiceContainer(); - $serviceContainer->setAdapterClass($connectionName, $config['adapter']); - $serviceContainer->setConnectionManager($connectionName, $manager); + $serviceContainer = Propel::getServiceContainer(); + $serviceContainer->setAdapterClass($connectionName, $config['adapter']); + $serviceContainer->setConnectionManager($connectionName, $manager); - $connection = Propel::getConnection($connectionName); + $connection = Propel::getConnection($connectionName); - $statement = $connection->prepare($query); - $statement->execute(); + $statement = $connection->prepare($query); + $statement->execute(); - $output->writeln(sprintf('Database %s has been created.', $dbName)); - } catch (\Exception $e) { - $this->writeSection($output, array( - '[Propel] Exception caught', - '', - $e->getMessage() - ), 'fg=white;bg=red'); - } + $output->writeln(sprintf('Database %s has been created.', $dbName)); } /** diff --git a/Command/DatabaseDropCommand.php b/Command/DatabaseDropCommand.php index 80fa856..bf17075 100644 --- a/Command/DatabaseDropCommand.php +++ b/Command/DatabaseDropCommand.php @@ -79,17 +79,9 @@ EOT $query = 'DROP DATABASE '. $dbName .';'; } - try { - $statement = $connection->prepare($query); - $statement->execute(); + $statement = $connection->prepare($query); + $statement->execute(); - $output->writeln(sprintf('Database %s has been dropped.', $dbName)); - } catch (\Exception $e) { - $this->writeSection($output, array( - '[Propel] Exception caught', - '', - $e->getMessage() - ), 'fg=white;bg=red'); - } + $output->writeln(sprintf('Database %s has been dropped.', $dbName)); } } diff --git a/Command/FixturesDumpCommand.php b/Command/FixturesDumpCommand.php index 36af2ef..e23330f 100644 --- a/Command/FixturesDumpCommand.php +++ b/Command/FixturesDumpCommand.php @@ -74,16 +74,7 @@ EOT $filename = $path . '/fixtures_' . time() . '.yml'; $dumper = $this->getContainer()->get('propel.dumper.yaml'); - try { - $dumper->dump($filename, $input->getOption('connection')); - } catch (\Exception $e) { - $this->writeSection($output, array( - '[Propel] Exception', - '', - $e->getMessage()), 'fg=white;bg=red'); - - return false; - } + $dumper->dump($filename, $input->getOption('connection')); $this->writeNewFile($output, $filename); diff --git a/Command/TableDropCommand.php b/Command/TableDropCommand.php index e6e48a4..812ef67 100644 --- a/Command/TableDropCommand.php +++ b/Command/TableDropCommand.php @@ -76,45 +76,37 @@ class TableDropCommand extends ContainerAwareCommand } } - try { - $showStatement = $connection->prepare('SHOW TABLES;'); - $showStatement->execute(); + $showStatement = $connection->prepare('SHOW TABLES;'); + $showStatement->execute(); - $allTables = $showStatement->fetchAll(\PDO::FETCH_COLUMN); + $allTables = $showStatement->fetchAll(\PDO::FETCH_COLUMN); - if ($nbTable) { - foreach ($tablesToDelete as $tableToDelete) { - if (!array_search($tableToDelete, $allTables)) { - throw new \InvalidArgumentException(sprintf('Table %s doesn\'t exist in the database.', $tableToDelete)); - } + if ($nbTable) { + foreach ($tablesToDelete as $tableToDelete) { + if (!array_search($tableToDelete, $allTables)) { + throw new \InvalidArgumentException(sprintf('Table %s doesn\'t exist in the database.', $tableToDelete)); } - } else { - $tablesToDelete = $allTables; } - - $connection->exec('SET FOREIGN_KEY_CHECKS = 0;'); - - array_walk($tablesToDelete, function (&$table, $key, $dbAdapter) { - $table = $dbAdapter->quoteIdentifierTable($table); - }, $adapter); - - $tablesToDelete = join(', ', $tablesToDelete); - - if ('' !== $tablesToDelete) { - $connection->exec('DROP TABLE ' . $tablesToDelete . ' ;'); - - $output->writeln(sprintf('Table' . $tablePlural . ' %s has been dropped.', $tablesToDelete)); - } else { - $output->writeln('No tables have been dropped'); - } - - $connection->exec('SET FOREIGN_KEY_CHECKS = 1;'); - } catch (\Exception $e) { - $this->writeSection($output, array( - '[Propel] Exception caught', - '', - $e->getMessage() - ), 'fg=white;bg=red'); + } else { + $tablesToDelete = $allTables; } + + $connection->exec('SET FOREIGN_KEY_CHECKS = 0;'); + + array_walk($tablesToDelete, function (&$table, $key, $dbAdapter) { + $table = $dbAdapter->quoteIdentifierTable($table); + }, $adapter); + + $tablesToDelete = join(', ', $tablesToDelete); + + if ('' !== $tablesToDelete) { + $connection->exec('DROP TABLE ' . $tablesToDelete . ' ;'); + + $output->writeln(sprintf('Table' . $tablePlural . ' %s has been dropped.', $tablesToDelete)); + } else { + $output->writeln('No tables have been dropped'); + } + + $connection->exec('SET FOREIGN_KEY_CHECKS = 1;'); } }