From 4dcdc0f3b9c6e4e1dbe71dad4f9600a39447619b Mon Sep 17 00:00:00 2001 From: William DURAND Date: Mon, 5 Sep 2011 22:18:18 +0200 Subject: [PATCH] [command] Naming + minor fixes on commands --- ...gCommand.php => AbstractPropelCommand.php} | 38 +++++++++---------- Command/BuildCommand.php | 4 +- Command/BuildModelCommand.php | 4 +- Command/BuildSqlCommand.php | 4 +- Command/DataDumpCommand.php | 4 +- Command/DataSqlCommand.php | 4 +- Command/DatabaseCreateCommand.php | 4 +- Command/DatabaseDropCommand.php | 4 +- Command/GraphvizCommand.php | 4 +- Command/InsertSqlCommand.php | 4 +- Command/LoadFixturesCommand.php | 18 +++++---- Command/MigrationGenerateDiffCommand.php | 4 +- Command/MigrationMigrateCommand.php | 4 +- Command/MigrationStatusCommand.php | 4 +- Command/ReverseCommand.php | 4 +- Command/TableDropCommand.php | 4 +- 16 files changed, 55 insertions(+), 57 deletions(-) rename Command/{PhingCommand.php => AbstractPropelCommand.php} (97%) diff --git a/Command/PhingCommand.php b/Command/AbstractPropelCommand.php similarity index 97% rename from Command/PhingCommand.php rename to Command/AbstractPropelCommand.php index 31e40ff..136257b 100644 --- a/Command/PhingCommand.php +++ b/Command/AbstractPropelCommand.php @@ -18,12 +18,12 @@ use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\HttpKernel\Util\Filesystem; /** - * Wrapper command for Phing tasks + * Wrapper for Propel commands. * * @author Fabien Potencier * @author William DURAND */ -abstract class PhingCommand extends ContainerAwareCommand +abstract class AbstractPropelCommand extends ContainerAwareCommand { /** * Additional Phing args to add in specialized commands. @@ -314,17 +314,13 @@ EOT; $properties = array(); if (false === $lines = @file($file)) { - throw new sfCommandException('Unable to parse contents of the "sqldb.map" file.'); + throw new \Exception(sprintf('Unable to parse contents of "%s".', $file)); } foreach ($lines as $line) { $line = trim($line); - if ('' == $line) { - continue; - } - - if (in_array($line[0], array('#', ';'))) { + if ('' == $line || in_array($line[0], array('#', ';'))) { continue; } @@ -363,7 +359,7 @@ EOT; throw new \InvalidArgumentException(sprintf('Connection named %s doesn\'t exist', $name)); } - $output->writeln(sprintf('[Propel] Use connection named %s', $name)); + $output->writeln(sprintf('Use connection named %s.', $name)); return array($name, $defaultConfig); } @@ -430,18 +426,6 @@ EOT; )); } - /** - * Ask confirmation from the user. - * - * @param OutputInterface $output The output. - * @param string $question A given question. - * @param string $default A default response. - */ - protected function askConfirmation(OutputInterface $output, $question, $default = null) - { - return $this->getHelperSet()->get('dialog')->askConfirmation($output, $question, $default); - } - /** * Renders an error message if a task has failed. * @@ -468,4 +452,16 @@ EOT; { return $output->writeln('>> File+ ' . $filename); } + + /** + * Ask confirmation from the user. + * + * @param OutputInterface $output The output. + * @param string $question A given question. + * @param string $default A default response. + */ + protected function askConfirmation(OutputInterface $output, $question, $default = null) + { + return $this->getHelperSet()->get('dialog')->askConfirmation($output, $question, $default); + } } diff --git a/Command/BuildCommand.php b/Command/BuildCommand.php index ea5b9d3..d8f1f9b 100644 --- a/Command/BuildCommand.php +++ b/Command/BuildCommand.php @@ -10,7 +10,7 @@ namespace Propel\PropelBundle\Command; -use Propel\PropelBundle\Command\PhingCommand; +use Propel\PropelBundle\Command\AbstractPropelCommand; use Propel\PropelBundle\Command\BuildModelCommand; use Propel\PropelBundle\Command\BuildSqlCommand; @@ -26,7 +26,7 @@ use Symfony\Component\Console\Output\Output; * @author Fabien Potencier * @author William DURAND */ -class BuildCommand extends PhingCommand +class BuildCommand extends AbstractPropelCommand { /** * @see Command diff --git a/Command/BuildModelCommand.php b/Command/BuildModelCommand.php index f7f3e54..12f8832 100644 --- a/Command/BuildModelCommand.php +++ b/Command/BuildModelCommand.php @@ -10,7 +10,7 @@ namespace Propel\PropelBundle\Command; -use Propel\PropelBundle\Command\PhingCommand; +use Propel\PropelBundle\Command\AbstractPropelCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -20,7 +20,7 @@ use Symfony\Component\Console\Output\OutputInterface; * @author Fabien Potencier * @author William DURAND */ -class BuildModelCommand extends PhingCommand +class BuildModelCommand extends AbstractPropelCommand { /** * @see Command diff --git a/Command/BuildSqlCommand.php b/Command/BuildSqlCommand.php index 5e3137c..ff34c23 100644 --- a/Command/BuildSqlCommand.php +++ b/Command/BuildSqlCommand.php @@ -18,7 +18,7 @@ use Symfony\Component\Console\Output\Output; use Symfony\Component\Finder\Finder; use Symfony\Component\HttpKernel\Util\Filesystem; -use Propel\PropelBundle\Command\PhingCommand; +use Propel\PropelBundle\Command\AbstractPropelCommand; /** * BuildCommand. @@ -26,7 +26,7 @@ use Propel\PropelBundle\Command\PhingCommand; * @author Fabien Potencier * @author William DURAND */ -class BuildSqlCommand extends PhingCommand +class BuildSqlCommand extends AbstractPropelCommand { /** * @see Command diff --git a/Command/DataDumpCommand.php b/Command/DataDumpCommand.php index 273c0b8..feec7df 100644 --- a/Command/DataDumpCommand.php +++ b/Command/DataDumpCommand.php @@ -10,7 +10,7 @@ namespace Propel\PropelBundle\Command; -use Propel\PropelBundle\Command\PhingCommand; +use Propel\PropelBundle\Command\AbstractPropelCommand; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -22,7 +22,7 @@ use Symfony\Component\HttpKernel\Util\Filesystem; * * @author William DURAND */ -class DataDumpCommand extends PhingCommand +class DataDumpCommand extends AbstractPropelCommand { protected static $destPath = '/propel/dump'; diff --git a/Command/DataSqlCommand.php b/Command/DataSqlCommand.php index a91ba6f..b081009 100644 --- a/Command/DataSqlCommand.php +++ b/Command/DataSqlCommand.php @@ -10,7 +10,7 @@ namespace Propel\PropelBundle\Command; -use Propel\PropelBundle\Command\PhingCommand; +use Propel\PropelBundle\Command\AbstractPropelCommand; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -22,7 +22,7 @@ use Symfony\Component\HttpKernel\Util\Filesystem; * * @author William DURAND */ -class DataSqlCommand extends PhingCommand +class DataSqlCommand extends AbstractPropelCommand { /** * @see Command diff --git a/Command/DatabaseCreateCommand.php b/Command/DatabaseCreateCommand.php index 4c40096..973e53c 100644 --- a/Command/DatabaseCreateCommand.php +++ b/Command/DatabaseCreateCommand.php @@ -10,7 +10,7 @@ namespace Propel\PropelBundle\Command; -use Propel\PropelBundle\Command\PhingCommand; +use Propel\PropelBundle\Command\AbstractPropelCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputOption; @@ -21,7 +21,7 @@ use Symfony\Component\Console\Input\InputOption; * * @author William DURAND */ -class DatabaseCreateCommand extends PhingCommand +class DatabaseCreateCommand extends AbstractPropelCommand { /** * @see Command diff --git a/Command/DatabaseDropCommand.php b/Command/DatabaseDropCommand.php index 27f3fe4..618775e 100644 --- a/Command/DatabaseDropCommand.php +++ b/Command/DatabaseDropCommand.php @@ -10,7 +10,7 @@ namespace Propel\PropelBundle\Command; -use Propel\PropelBundle\Command\PhingCommand; +use Propel\PropelBundle\Command\AbstractPropelCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputOption; @@ -21,7 +21,7 @@ use Symfony\Component\Console\Input\InputOption; * * @author William DURAND */ -class DatabaseDropCommand extends PhingCommand +class DatabaseDropCommand extends AbstractPropelCommand { /** * @see Command diff --git a/Command/GraphvizCommand.php b/Command/GraphvizCommand.php index dfae85d..f64f722 100644 --- a/Command/GraphvizCommand.php +++ b/Command/GraphvizCommand.php @@ -10,7 +10,7 @@ namespace Propel\PropelBundle\Command; -use Propel\PropelBundle\Command\PhingCommand; +use Propel\PropelBundle\Command\AbstractPropelCommand; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -20,7 +20,7 @@ use Symfony\Component\Console\Output\OutputInterface; * * @author William DURAND */ -class GraphvizCommand extends PhingCommand +class GraphvizCommand extends AbstractPropelCommand { /** * @see Command diff --git a/Command/InsertSqlCommand.php b/Command/InsertSqlCommand.php index 813fb4d..9efb52d 100644 --- a/Command/InsertSqlCommand.php +++ b/Command/InsertSqlCommand.php @@ -10,7 +10,7 @@ namespace Propel\PropelBundle\Command; -use Propel\PropelBundle\Command\PhingCommand; +use Propel\PropelBundle\Command\AbstractPropelCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -20,7 +20,7 @@ use Symfony\Component\Console\Output\OutputInterface; * * @author William DURAND */ -class InsertSqlCommand extends PhingCommand +class InsertSqlCommand extends AbstractPropelCommand { /** * @see Command diff --git a/Command/LoadFixturesCommand.php b/Command/LoadFixturesCommand.php index 55b794d..7d156f9 100644 --- a/Command/LoadFixturesCommand.php +++ b/Command/LoadFixturesCommand.php @@ -17,7 +17,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Finder\Finder; use Symfony\Component\HttpKernel\Util\Filesystem; -use Propel\PropelBundle\Command\PhingCommand; +use Propel\PropelBundle\Command\AbstractPropelCommand; use Propel\PropelBundle\DataFixtures\YamlDataLoader; use Propel\PropelBundle\DataFixtures\XmlDataLoader; @@ -26,7 +26,7 @@ use Propel\PropelBundle\DataFixtures\XmlDataLoader; * * @author William DURAND */ -class LoadFixturesCommand extends PhingCommand +class LoadFixturesCommand extends AbstractPropelCommand { /** * Default fixtures directory. @@ -124,26 +124,26 @@ EOT } if (!$this->absoluteFixturesPath && !file_exists($this->absoluteFixturesPath)) { - return $output->writeln('[Propel] The fixtures directory does not exist.'); + return $output->writeln('The fixtures directory does not exist.'); } $noOptions = (!$input->getOption('xml') && !$input->getOption('sql') && !$input->getOption('yml')); if ($input->getOption('sql') || $noOptions) { if (-1 === $this->loadSqlFixtures($input, $output)) { - $output->writeln('[Propel] No SQL fixtures found.'); + $output->writeln('No SQL fixtures found.'); } } if ($input->getOption('xml') || $noOptions) { if (-1 === $this->loadFixtures($input, $output, 'xml')) { - $output->writeln('[Propel] No XML fixtures found.'); + $output->writeln('No XML fixtures found.'); } } if ($input->getOption('yml') || $noOptions) { if (-1 === $this->loadFixtures($input, $output, 'yml')) { - $output->writeln('[Propel] No YAML fixtures found.'); + $output->writeln('No YAML fixtures found.'); } } } @@ -218,7 +218,7 @@ EOT // Create a "sqldb.map" file $sqldbContent = ''; foreach($datas as $data) { - $output->writeln(sprintf('[Propel] Loading SQL fixtures from %s', $data)); + $output->writeln(sprintf('Loading SQL fixtures from %s.', $data)); $sqldbContent .= $data->getFilename() . '=' . $name . PHP_EOL; $this->filesystem->copy($data, $tmpdir . '/fixtures/' . $data->getFilename(), true); @@ -272,7 +272,9 @@ EOT )); if (true === $ret) { - $output->writeln('[Propel] All SQL statements have been executed.'); + $this->writeSection($output, array( + '', 'All SQL statements have been executed.' + ), 'fg=green;bg=black'); } else { $this->writeTaskError($output, 'insert-sql', false); return false; diff --git a/Command/MigrationGenerateDiffCommand.php b/Command/MigrationGenerateDiffCommand.php index b794048..92f8dd1 100644 --- a/Command/MigrationGenerateDiffCommand.php +++ b/Command/MigrationGenerateDiffCommand.php @@ -10,7 +10,7 @@ namespace Propel\PropelBundle\Command; -use Propel\PropelBundle\Command\PhingCommand; +use Propel\PropelBundle\Command\AbstractPropelCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -19,7 +19,7 @@ use Symfony\Component\Console\Output\OutputInterface; * * @author William DURAND */ -class MigrationGenerateDiffCommand extends PhingCommand +class MigrationGenerateDiffCommand extends AbstractPropelCommand { /** * @see Command diff --git a/Command/MigrationMigrateCommand.php b/Command/MigrationMigrateCommand.php index 61abc55..f492f69 100644 --- a/Command/MigrationMigrateCommand.php +++ b/Command/MigrationMigrateCommand.php @@ -10,7 +10,7 @@ namespace Propel\PropelBundle\Command; -use Propel\PropelBundle\Command\PhingCommand; +use Propel\PropelBundle\Command\AbstractPropelCommand; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -21,7 +21,7 @@ use Symfony\Component\Console\Output\Output; * * @author William DURAND */ -class MigrationMigrateCommand extends PhingCommand +class MigrationMigrateCommand extends AbstractPropelCommand { /** * @see Command diff --git a/Command/MigrationStatusCommand.php b/Command/MigrationStatusCommand.php index 39114eb..4889d5f 100644 --- a/Command/MigrationStatusCommand.php +++ b/Command/MigrationStatusCommand.php @@ -10,7 +10,7 @@ namespace Propel\PropelBundle\Command; -use Propel\PropelBundle\Command\PhingCommand; +use Propel\PropelBundle\Command\AbstractPropelCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -19,7 +19,7 @@ use Symfony\Component\Console\Output\OutputInterface; * * @author William DURAND */ -class MigrationStatusCommand extends PhingCommand +class MigrationStatusCommand extends AbstractPropelCommand { /** * @see Command diff --git a/Command/ReverseCommand.php b/Command/ReverseCommand.php index 126edc4..b3f0bb6 100644 --- a/Command/ReverseCommand.php +++ b/Command/ReverseCommand.php @@ -10,7 +10,7 @@ namespace Propel\PropelBundle\Command; -use Propel\PropelBundle\Command\PhingCommand; +use Propel\PropelBundle\Command\AbstractPropelCommand; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -22,7 +22,7 @@ use Symfony\Component\HttpKernel\Util\Filesystem; * * @author William DURAND */ -class ReverseCommand extends PhingCommand +class ReverseCommand extends AbstractPropelCommand { /** * @see Command diff --git a/Command/TableDropCommand.php b/Command/TableDropCommand.php index 5131255..ab9535a 100644 --- a/Command/TableDropCommand.php +++ b/Command/TableDropCommand.php @@ -10,7 +10,7 @@ namespace Propel\PropelBundle\Command; -use Propel\PropelBundle\Command\PhingCommand; +use Propel\PropelBundle\Command\AbstractPropelCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputOption; @@ -22,7 +22,7 @@ use Symfony\Component\Console\Input\InputArgument; * * @author Maxime AILLOUD */ -class TableDropCommand extends PhingCommand +class TableDropCommand extends AbstractPropelCommand { /** * @see Command