diff --git a/Command/BuildModelCommand.php b/Command/BuildModelCommand.php
index 96e1384..2a6445e 100644
--- a/Command/BuildModelCommand.php
+++ b/Command/BuildModelCommand.php
@@ -46,22 +46,24 @@ EOT
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
+ $this->writeSection($output, '[Propel] You are running the command: propel:build-model');
+
if ($input->getOption('verbose')) {
$this->additionalPhingArgs[] = 'verbose';
}
- $this->writeSection($output, '[Propel] You are running the command: propel:build-model');
-
if (true === $this->callPhing('om')) {
foreach ($this->tempSchemas as $schemaFile => $schemaDetails) {
- $output->writeln(sprintf(
- 'Built Model classes for bundle %s from %s.',
- $schemaDetails['bundle'],
- $schemaDetails['path']
- ));
+ if (file_exists($schemaFile)) {
+ $output->writeln(sprintf(
+ 'Built Model classes for bundle %s from %s.',
+ $schemaDetails['bundle'],
+ $schemaDetails['path']
+ ));
+ }
}
} else {
- $output->writeln('WARNING ! An error has occured.');
+ $this->writeTaskError('om');
}
}
}
diff --git a/Command/DataDumpCommand.php b/Command/DataDumpCommand.php
index 9dae1fa..3b683b4 100644
--- a/Command/DataDumpCommand.php
+++ b/Command/DataDumpCommand.php
@@ -76,12 +76,14 @@ EOT
$filesystem->copy((string) $data, $dest);
$filesystem->remove($data);
- $output->writeln(sprintf('Wrote dumped data in %s.', $dest));
+ $output->writeln(sprintf('Wrote dumped data in %s.', $dest));
}
if (iterator_count($datas) <= 0) {
$output->writeln('No dumped files.');
}
+ } else {
+ $this->writeTaskError('datadump', false);
}
}
}
diff --git a/Command/DataSqlCommand.php b/Command/DataSqlCommand.php
index fbc73c0..773d87f 100644
--- a/Command/DataSqlCommand.php
+++ b/Command/DataSqlCommand.php
@@ -64,18 +64,22 @@ EOT
$filesystem->copy((string) $data, $schemaDir . $data->getFilename());
}
- $this->callPhing('datasql', array(
- 'propel.sql.dir' => $sqlDir,
- 'propel.schema.dir' => $schemaDir,
+ $ret = $this->callPhing('datasql', array(
+ 'propel.sql.dir' => $sqlDir,
+ 'propel.schema.dir' => $schemaDir,
));
- $finder = new Finder();
- foreach($finder->name('*_data.xml')->in($schemaDir) as $data) {
- $filesystem->remove($data);
- }
+ if ($ret) {
+ $finder = new Finder();
+ foreach($finder->name('*_data.xml')->in($schemaDir) as $data) {
+ $filesystem->remove($data);
+ }
- $this->writeSummary($output, 'propel-data-sql');
- $output->writeln(sprintf('SQL from XML data dump file is in %s.', $sqlDir));
+ $this->writeSummary($output, 'propel-data-sql');
+ $output->writeln(sprintf('SQL from XML data dump file is in %s.', $sqlDir));
+ } else {
+ $this->writeTaskError('datasql', false);
+ }
}
}
diff --git a/Command/DatabaseCreateCommand.php b/Command/DatabaseCreateCommand.php
index 56d9173..4c40096 100644
--- a/Command/DatabaseCreateCommand.php
+++ b/Command/DatabaseCreateCommand.php
@@ -54,9 +54,13 @@ class DatabaseCreateCommand extends PhingCommand
$statement = $connection->prepare($query);
$statement->execute();
- $output->writeln(sprintf('[Propel] %s has been created.', $dbName));
+ $output->writeln(sprintf('Database %s has been created.', $dbName));
} catch (\Exception $e) {
- $this->writeSection($output, array('[Propel] Exception catched', '', $e->getMessage()), 'fg=white;bg=red');
+ $this->writeSection($output, array(
+ '[Propel] Exception catched',
+ '',
+ $e->getMessage()
+ ), 'fg=white;bg=red');
}
}
diff --git a/Command/DatabaseDropCommand.php b/Command/DatabaseDropCommand.php
index 2776986..cfbb6a9 100644
--- a/Command/DatabaseDropCommand.php
+++ b/Command/DatabaseDropCommand.php
@@ -73,12 +73,16 @@ EOT
$statement = $connection->prepare($query);
$statement->execute();
- $output->writeln(sprintf('[Propel] %s has been dropped.', $dbName));
+ $output->writeln(sprintf('Database %s has been dropped.', $dbName));
} catch (\Exception $e) {
- $this->writeSection($output, array('[Propel] Exception catched', '', $e->getMessage()), 'fg=white;bg=red');
+ $this->writeSection($output, array(
+ '[Propel] Exception catched',
+ '',
+ $e->getMessage()
+ ), 'fg=white;bg=red');
}
} else {
- $output->writeln('[Propel] You have to use --force to drop the database.');
+ $output->writeln('You have to use --force to drop the database.');
}
}
}
diff --git a/Command/InsertSqlCommand.php b/Command/InsertSqlCommand.php
index 6d4ee6e..1135e10 100644
--- a/Command/InsertSqlCommand.php
+++ b/Command/InsertSqlCommand.php
@@ -55,6 +55,10 @@ EOT
if ($input->getOption('force')) {
$this->writeSection($output, '[Propel] You are running the command: propel:insert-sql');
+ if ($input->getOption('verbose')) {
+ $this->additionalPhingArgs[] = 'verbose';
+ }
+
list($name, $defaultConfig) = $this->getConnection($input, $output);
$ret = $this->callPhing('insert-sql', array(
@@ -68,7 +72,7 @@ EOT
if (true === $ret) {
$output->writeln('All SQL statements have been executed.');
} else {
- $output->writeln('WARNING ! An error has occured.');
+ $this->writeTaskError('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 5ef3019..853f112 100644
--- a/Command/LoadFixturesCommand.php
+++ b/Command/LoadFixturesCommand.php
@@ -141,11 +141,7 @@ EOT
));
if ($ret === false) {
- $this->writeSection($output, array(
- '[Propel] Error',
- '',
- 'An error has occured during the "datasql" task process. To get more details, run the command with the "--verbose" option.'
- ), 'fg=white;bg=red');
+ $this->writeTaskError('datasql');
return -2;
}
@@ -257,7 +253,7 @@ EOT
if (true === $ret) {
$output->writeln('[Propel] All SQL statements have been executed.');
} else {
- $this->writeSection($output, '[Propel] WARNING ! An error has occured.', 'fg=white;bg=red');
+ $this->writeTaskError('insert-sql', false);
return false;
}
diff --git a/Command/PhingCommand.php b/Command/PhingCommand.php
index ed42543..f102ce9 100644
--- a/Command/PhingCommand.php
+++ b/Command/PhingCommand.php
@@ -440,4 +440,20 @@ EOT;
{
return $this->getHelperSet()->get('dialog')->askConfirmation($output, $question, $default);
}
+
+ /**
+ * Renders an error message if a task has failed.
+ *
+ * @param string $taskName A task name.
+ */
+ protected function writeTaskError($taskName, $more = true)
+ {
+ $moreText = $more ? ' To get more details, run the command with the "--verbose" option.' : '';
+
+ return $this->writeSection($output, array(
+ '[Propel] Error',
+ '',
+ 'An error has occured during the "' . $taskName . '" task process.' . $moreText
+ ), 'fg=white;bg=red');
+ }
}
diff --git a/Command/TableDropCommand.php b/Command/TableDropCommand.php
index ff2230a..7c6689a 100644
--- a/Command/TableDropCommand.php
+++ b/Command/TableDropCommand.php
@@ -62,10 +62,16 @@ EOT
$tablePlural = (($nbTable > 1 || $nbTable == 0) ? 's' : '' );
if ('prod' === $this->getApplication()->getKernel()->getEnvironment()) {
- $this->writeSection($output, 'WARNING: you are about to drop ' . (count($input->getArgument('table')) ?: 'all') . ' table' . $tablePlural . ' in production !', 'bg=red;fg=white');
+ $count = (count($input->getArgument('table')) ?: 'all');
+
+ $this->writeSection(
+ $output,
+ 'WARNING: you are about to drop ' . $count . ' table' . $tablePlural . ' in production !',
+ 'bg=red;fg=white'
+ );
if (false === $this->askConfirmation($output, 'Are you sure ? (y/n) ', false)) {
- $output->writeln('Aborted, nice decision !');
+ $output->writeln('Aborted, nice decision !');
return -2;
}
}
@@ -102,13 +108,17 @@ EOT
$output->writeln(sprintf('Table' . $tablePlural . ' %s has been dropped.', $tablesToDelete));
}
else {
- $output->writeln('No table has been dropped');
+ $output->writeln('No tables have been dropped');
}
$connection->exec('SET FOREIGN_KEY_CHECKS = 1;');
}
catch (\Exception $e) {
- $output->writeln(sprintf('An error has occured: %s', $e->getMessage()));
+ $this->writeSection($output, array(
+ '[Propel] Exception catched',
+ '',
+ $e->getMessage()
+ ), 'fg=white;bg=red');
}
}
else {