Skip to content
Browse files

[command] Fixed output (for real)

  • Loading branch information...
1 parent e35ae76 commit f18df260fe8e9056c5d169c1937d4e1bb573fca2 @willdurand willdurand committed Aug 31, 2011
View
14 Command/BuildModelCommand.php
@@ -54,16 +54,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (true === $this->callPhing('om')) {
foreach ($this->tempSchemas as $schemaFile => $schemaDetails) {
- if (file_exists($schemaFile)) {
- $output->writeln(sprintf(
- 'Built Model classes for bundle <info>%s</info> from <comment>%s</comment>.',
- $schemaDetails['bundle'],
- $schemaDetails['path']
- ));
- }
+ $output->writeln(sprintf(
+ '>> <info>%s</info> Generated model classes from <comment>%s</comment>',
+ $schemaDetails['bundle'],
+ $schemaDetails['basename']
+ ));
}
} else {
- $this->writeTaskError('om');
+ $this->writeTaskError($output, 'om');
}
}
}
View
48 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 @@ protected function execute(InputInterface $input, OutputInterface $output)
$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';
- $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($sqlDir);
+ $filesystem->mkdir($sqlDir);
- $filesystem->remove($targetSqlFilePath);
- $filesystem->rename($basePath . DIRECTORY_SEPARATOR . $sqlFile, $targetSqlFilePath);
+ // Execute the task
+ $ret = $this->callPhing('sql', array(
+ 'propel.packageObjectModel' => true,
+ ));
- $output->writeln(sprintf(
- 'Wrote SQL file for bundle <info>%s</info> in <comment>%s</comment>.',
- $schemaDetails['bundle'],
- $targetSqlFilePath)
- );
+ if (true === $ret) {
+ $files = $finder->name('*')->in($sqlDir);
+
+ $nbFiles = 0;
+ foreach ($files as $file) {
+ $this->writeNewFile($output, (string) $file);
+
+ if ('sql' === $file->getExtension()) {
+ $nbFiles++;
+ }
}
- file_put_contents($basePath . DIRECTORY_SEPARATOR . 'sqldb.map', $sqlMap);
+ $this->writeSection(
+ $output,
+ sprintf('<comment>%d</comment> <info>SQL file have been generated.</info>', $nbFiles),
+ 'bg=black'
+ );
} else {
$this->writeSection($output, array(
'[Propel] Error',
View
2 Command/DataDumpCommand.php
@@ -83,7 +83,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln('No dumped files.');
}
} else {
- $this->writeTaskError('datadump', false);
+ $this->writeTaskError($output, 'datadump', false);
}
}
}
View
2 Command/DataSqlCommand.php
@@ -78,7 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->writeSummary($output, 'propel-data-sql');
$output->writeln(sprintf('<info>SQL from XML data dump file is in <comment>%s</comment></info>.', $sqlDir));
} else {
- $this->writeTaskError('datasql', false);
+ $this->writeTaskError($output, 'datasql', false);
}
}
}
View
2 Command/InsertSqlCommand.php
@@ -72,7 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (true === $ret) {
$output->writeln('<info>All SQL statements have been executed.</info>');
} else {
- $this->writeTaskError('insert-sql');
+ $this->writeTaskError($output, 'insert-sql');
}
} else {
$output->writeln('<error>You have to use --force to execute all SQL statements.</error>');
View
4 Command/LoadFixturesCommand.php
@@ -141,7 +141,7 @@ protected function loadXmlFixtures(InputInterface $input, OutputInterface $outpu
));
if ($ret === false) {
- $this->writeTaskError('datasql');
+ $this->writeTaskError($output, 'datasql');
return -2;
}
@@ -253,7 +253,7 @@ protected function insertSql($config, $sqlDir, $schemaDir, $output)
if (true === $ret) {
$output->writeln('<info>[Propel] All SQL statements have been executed.</info>');
} else {
- $this->writeTaskError('insert-sql', false);
+ $this->writeTaskError($output, 'insert-sql', false);
return false;
}
View
13 Command/PhingCommand.php
@@ -444,9 +444,11 @@ protected function askConfirmation(OutputInterface $output, $question, $default
/**
* 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 @@ protected function writeTaskError($taskName, $more = true)
'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('>> <info>File+</info> ' . $filename);
+ }
}

0 comments on commit f18df26

Please sign in to comment.
Something went wrong with that request. Please try again.