From f18df260fe8e9056c5d169c1937d4e1bb573fca2 Mon Sep 17 00:00:00 2001 From: William DURAND Date: Wed, 31 Aug 2011 16:12:56 +0200 Subject: [PATCH] [command] Fixed output (for real) --- Command/BuildModelCommand.php | 14 ++++----- Command/BuildSqlCommand.php | 52 ++++++++++++++++++--------------- Command/DataDumpCommand.php | 2 +- Command/DataSqlCommand.php | 2 +- Command/InsertSqlCommand.php | 2 +- Command/LoadFixturesCommand.php | 4 +-- Command/PhingCommand.php | 13 ++++++++- 7 files changed, 52 insertions(+), 37 deletions(-) diff --git a/Command/BuildModelCommand.php b/Command/BuildModelCommand.php index 2a6445e..f7f3e54 100644 --- a/Command/BuildModelCommand.php +++ b/Command/BuildModelCommand.php @@ -54,16 +54,14 @@ EOT if (true === $this->callPhing('om')) { foreach ($this->tempSchemas as $schemaFile => $schemaDetails) { - if (file_exists($schemaFile)) { - $output->writeln(sprintf( - 'Built Model classes for bundle %s from %s.', - $schemaDetails['bundle'], - $schemaDetails['path'] - )); - } + $output->writeln(sprintf( + '>> %s Generated model classes from %s', + $schemaDetails['bundle'], + $schemaDetails['basename'] + )); } } else { - $this->writeTaskError('om'); + $this->writeTaskError($output, 'om'); } } } diff --git a/Command/BuildSqlCommand.php b/Command/BuildSqlCommand.php index 2a22a92..d221d01 100644 --- a/Command/BuildSqlCommand.php +++ b/Command/BuildSqlCommand.php @@ -10,14 +10,16 @@ namespace Propel\PropelBundle\Command; -use Propel\PropelBundle\Command\PhingCommand; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\Output; +use Symfony\Component\Finder\Finder; use Symfony\Component\HttpKernel\Util\Filesystem; +use Propel\PropelBundle\Command\PhingCommand; + /** * BuildCommand. * @@ -56,32 +58,36 @@ EOT $this->additionalPhingArgs[] = 'verbose'; } - if (true === $this->callPhing('sql', array('propel.packageObjectModel' => true))) { - $filesystem = new Filesystem(); - $basePath = $this->getApplication()->getKernel()->getRootDir(). DIRECTORY_SEPARATOR . 'propel'. DIRECTORY_SEPARATOR . 'sql'; - $sqlMap = file_get_contents($basePath . DIRECTORY_SEPARATOR . 'sqldb.map'); + $finder = new Finder(); + $filesystem = new Filesystem(); - foreach ($this->tempSchemas as $schemaFile => $schemaDetails) { - if (!file_exists($schemaFile)) { - continue; + $sqlDir = $this->getApplication()->getKernel()->getRootDir(). DIRECTORY_SEPARATOR . 'propel'. DIRECTORY_SEPARATOR . 'sql'; + + $filesystem->remove($sqlDir); + $filesystem->mkdir($sqlDir); + + // Execute the task + $ret = $this->callPhing('sql', array( + 'propel.packageObjectModel' => true, + )); + + if (true === $ret) { + $files = $finder->name('*')->in($sqlDir); + + $nbFiles = 0; + foreach ($files as $file) { + $this->writeNewFile($output, (string) $file); + + if ('sql' === $file->getExtension()) { + $nbFiles++; } - - $sqlFile = str_replace('.xml', '.sql', $schemaFile); - $targetSqlFile = $schemaDetails['bundle'] . '-' . str_replace('.xml', '.sql', $schemaDetails['basename']); - $targetSqlFilePath = $basePath . DIRECTORY_SEPARATOR . $targetSqlFile; - $sqlMap = str_replace($sqlFile, $targetSqlFile, $sqlMap); - - $filesystem->remove($targetSqlFilePath); - $filesystem->rename($basePath . DIRECTORY_SEPARATOR . $sqlFile, $targetSqlFilePath); - - $output->writeln(sprintf( - 'Wrote SQL file for bundle %s in %s.', - $schemaDetails['bundle'], - $targetSqlFilePath) - ); } - file_put_contents($basePath . DIRECTORY_SEPARATOR . 'sqldb.map', $sqlMap); + $this->writeSection( + $output, + sprintf('%d SQL file have been generated.', $nbFiles), + 'bg=black' + ); } else { $this->writeSection($output, array( '[Propel] Error', diff --git a/Command/DataDumpCommand.php b/Command/DataDumpCommand.php index 3b683b4..4d034e8 100644 --- a/Command/DataDumpCommand.php +++ b/Command/DataDumpCommand.php @@ -83,7 +83,7 @@ EOT $output->writeln('No dumped files.'); } } else { - $this->writeTaskError('datadump', false); + $this->writeTaskError($output, 'datadump', false); } } } diff --git a/Command/DataSqlCommand.php b/Command/DataSqlCommand.php index 773d87f..a91ba6f 100644 --- a/Command/DataSqlCommand.php +++ b/Command/DataSqlCommand.php @@ -78,7 +78,7 @@ EOT $this->writeSummary($output, 'propel-data-sql'); $output->writeln(sprintf('SQL from XML data dump file is in %s.', $sqlDir)); } else { - $this->writeTaskError('datasql', false); + $this->writeTaskError($output, 'datasql', false); } } } diff --git a/Command/InsertSqlCommand.php b/Command/InsertSqlCommand.php index 1135e10..a60b386 100644 --- a/Command/InsertSqlCommand.php +++ b/Command/InsertSqlCommand.php @@ -72,7 +72,7 @@ EOT if (true === $ret) { $output->writeln('All SQL statements have been executed.'); } else { - $this->writeTaskError('insert-sql'); + $this->writeTaskError($output, 'insert-sql'); } } else { $output->writeln('You have to use --force to execute all SQL statements.'); diff --git a/Command/LoadFixturesCommand.php b/Command/LoadFixturesCommand.php index 853f112..9d56bb3 100644 --- a/Command/LoadFixturesCommand.php +++ b/Command/LoadFixturesCommand.php @@ -141,7 +141,7 @@ EOT )); if ($ret === false) { - $this->writeTaskError('datasql'); + $this->writeTaskError($output, 'datasql'); return -2; } @@ -253,7 +253,7 @@ EOT if (true === $ret) { $output->writeln('[Propel] All SQL statements have been executed.'); } else { - $this->writeTaskError('insert-sql', false); + $this->writeTaskError($output, 'insert-sql', false); return false; } diff --git a/Command/PhingCommand.php b/Command/PhingCommand.php index f102ce9..72d5163 100644 --- a/Command/PhingCommand.php +++ b/Command/PhingCommand.php @@ -444,9 +444,11 @@ EOT; /** * Renders an error message if a task has failed. * + * @param OutputInterface $output The output. * @param string $taskName A task name. + * @param Boolean $more Whether to add a 'more details' message or not. */ - protected function writeTaskError($taskName, $more = true) + protected function writeTaskError($output, $taskName, $more = true) { $moreText = $more ? ' To get more details, run the command with the "--verbose" option.' : ''; @@ -456,4 +458,13 @@ EOT; 'An error has occured during the "' . $taskName . '" task process.' . $moreText ), 'fg=white;bg=red'); } + + /** + * @param OutputInterface $output The output. + * @param string $filename The filename. + */ + protected function writeNewFile($output, $filename) + { + return $output->writeln('>> File+ ' . $filename); + } }