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
This commit is contained in:
Maxim 2016-05-27 23:07:47 +10:00 committed by Marc J. Schmidt
parent 830e68f344
commit cdcb3f6b9f
4 changed files with 40 additions and 73 deletions

View file

@ -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('<info>Database <comment>%s</comment> has been created.</info>', $dbName));
} catch (\Exception $e) {
$this->writeSection($output, array(
'[Propel] Exception caught',
'',
$e->getMessage()
), 'fg=white;bg=red');
}
$output->writeln(sprintf('<info>Database <comment>%s</comment> has been created.</info>', $dbName));
}
/**

View file

@ -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('<info>Database <comment>%s</comment> has been dropped.</info>', $dbName));
} catch (\Exception $e) {
$this->writeSection($output, array(
'[Propel] Exception caught',
'',
$e->getMessage()
), 'fg=white;bg=red');
}
$output->writeln(sprintf('<info>Database <comment>%s</comment> has been dropped.</info>', $dbName));
}
}

View file

@ -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);

View file

@ -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 . ' <info><comment>%s</comment> has been dropped.</info>', $tablesToDelete));
} else {
$output->writeln('<info>No tables have been dropped</info>');
}
$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 . ' <info><comment>%s</comment> has been dropped.</info>', $tablesToDelete));
} else {
$output->writeln('<info>No tables have been dropped</info>');
}
$connection->exec('SET FOREIGN_KEY_CHECKS = 1;');
}
}