Permalink
Browse files

Added a way to detect errors during Phing execution

  • Loading branch information...
1 parent d9862f6 commit 4c07e38ce38d98c3644c0ac4d7021d40d58f3672 @willdurand willdurand committed Jun 20, 2011
Showing with 52 additions and 30 deletions.
  1. +10 −3 Command/BuildModelCommand.php
  2. +21 −14 Command/BuildSqlCommand.php
  3. +6 −2 Command/InsertSqlCommand.php
  4. +15 −11 Command/PhingCommand.php
@@ -41,10 +41,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($input->getOption('verbose')) {
$this->additionalPhingArgs[]= 'verbose';
}
- $this->callPhing('om');
- foreach ($this->tempSchemas as $schemaFile => $schemaDetails) {
- $output->writeln(sprintf('Built Model classes for bundle <info>%s</info> from <comment>%s</comment>.', $schemaDetails['bundle'], $schemaDetails['path']));
+ if (true === $this->callPhing('om')) {
+ foreach ($this->tempSchemas as $schemaFile => $schemaDetails) {
+ $output->writeln(sprintf(
+ 'Built Model classes for bundle <info>%s</info> from <comment>%s</comment>.',
+ $schemaDetails['bundle'],
+ $schemaDetails['path']
+ ));
+ }
+ } else {
+ $output->writeln('<error>WARNING ! An error has occured.</error>');
}
}
}
@@ -45,23 +45,30 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($input->getOption('verbose')) {
$this->additionalPhingArgs[]= 'verbose';
}
- $this->callPhing('sql', array('propel.packageObjectModel' => false));
- $filesystem = new Filesystem();
- $basePath = $this->getApplication()->getKernel()->getRootDir(). DIRECTORY_SEPARATOR . 'propel'. DIRECTORY_SEPARATOR . 'sql';
- $sqlMap = file_get_contents($basePath . DIRECTORY_SEPARATOR . 'sqldb.map');
+ if (true === $this->callPhing('sql', array('propel.packageObjectModel' => false))) {
+ $filesystem = new Filesystem();
+ $basePath = $this->getApplication()->getKernel()->getRootDir(). DIRECTORY_SEPARATOR . 'propel'. DIRECTORY_SEPARATOR . 'sql';
+ $sqlMap = file_get_contents($basePath . DIRECTORY_SEPARATOR . 'sqldb.map');
- foreach ($this->tempSchemas as $schemaFile => $schemaDetails) {
- $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);
+ foreach ($this->tempSchemas as $schemaFile => $schemaDetails) {
+ $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 <info>%s</info> in <comment>%s</comment>.', $schemaDetails['bundle'], $targetSqlFilePath));
- }
+ $output->writeln(sprintf(
+ 'Wrote SQL file for bundle <info>%s</info> in <comment>%s</comment>.',
+ $schemaDetails['bundle'],
+ $targetSqlFilePath)
+ );
+ }
- file_put_contents($basePath . DIRECTORY_SEPARATOR . 'sqldb.map', $sqlMap);
+ file_put_contents($basePath . DIRECTORY_SEPARATOR . 'sqldb.map', $sqlMap);
+ } else {
+ $output->writeln('<error>WARNING ! An error has occured.</error>');
+ }
}
}
@@ -47,15 +47,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($input->getOption('force')) {
list($name, $defaultConfig) = $this->getConnection($input, $output);
- $this->callPhing('insert-sql', array(
+ $ret = $this->callPhing('insert-sql', array(
'propel.database.url' => $defaultConfig['connection']['dsn'],
'propel.database.database' => $defaultConfig['adapter'],
'propel.database.user' => $defaultConfig['connection']['user'],
'propel.database.password' => $defaultConfig['connection']['password'],
'propel.schema.dir' => $this->getApplication()->getKernel()->getRootDir() . '/propel/schema/',
));
- $output->writeln('<info>All SQL statements have been executed.</info>');
+ if (true === $ret) {
+ $output->writeln('<info>All SQL statements have been executed.</info>');
+ } else {
+ $output->writeln('<error>WARNING ! An error has occured.</error>');
+ }
} else {
$output->writeln('<error>You have to use --force to execute all SQL statements.</error>');
}
@@ -126,7 +126,7 @@ protected function callPhing($taskName, $properties = array())
$args[] = '-f';
$args[] = realpath($kernel->getContainer()->getParameter('propel.path').'/generator/build.xml');
- $bufferPhingOutput = !$kernel->getContainer()->getParameter('kernel.debug');
+ $bufferPhingOutput = true; //!$kernel->getContainer()->getParameter('kernel.debug');
// Add any arbitrary arguments last
foreach ($this->additionalPhingArgs as $arg) {
@@ -141,26 +141,30 @@ protected function callPhing($taskName, $properties = array())
// enable output buffering
Phing::setOutputStream(new \OutputStream(fopen('php://output', 'w')));
+ Phing::setErrorStream(new \OutputStream(fopen('php://output', 'w')));
Phing::startup();
Phing::setProperty('phing.home', getenv('PHING_HOME'));
- if ($bufferPhingOutput) {
- ob_start();
- }
+ ob_start();
+
+ $phing = new Phing();
+ $returnStatus = true; // optimistic way
- $m = new Phing();
- $m->execute($args);
- $m->runBuild();
+ try {
+ $phing->execute($args);
+ $phing->runBuild();
- if ($bufferPhingOutput) {
$this->buffer = ob_get_contents();
- ob_end_clean();
+ $returnStatus = false !== preg_match('#failed. Aborting.#', $this->buffer);
+ } catch(Exception $e) {
+ $returnStatus = false;
}
+ ob_end_flush();
+
chdir($kernel->getRootDir());
- $ret = true;
- return $ret;
+ return $returnStatus;
}
/**

0 comments on commit 4c07e38

Please sign in to comment.