diff --git a/Command/BuildModelCommand.php b/Command/BuildModelCommand.php index fc11116..031009c 100644 --- a/Command/BuildModelCommand.php +++ b/Command/BuildModelCommand.php @@ -41,10 +41,17 @@ EOT if ($input->getOption('verbose')) { $this->additionalPhingArgs[]= 'verbose'; } - $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 (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'] + )); + } + } else { + $output->writeln('WARNING ! An error has occured.'); } } } diff --git a/Command/BuildSqlCommand.php b/Command/BuildSqlCommand.php index 5dd9cf3..75e2c77 100644 --- a/Command/BuildSqlCommand.php +++ b/Command/BuildSqlCommand.php @@ -45,23 +45,30 @@ EOT 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 %s in %s.', $schemaDetails['bundle'], $targetSqlFilePath)); + $output->writeln(sprintf( + 'Wrote SQL file for bundle %s in %s.', + $schemaDetails['bundle'], + $targetSqlFilePath) + ); + } + + file_put_contents($basePath . DIRECTORY_SEPARATOR . 'sqldb.map', $sqlMap); + } else { + $output->writeln('WARNING ! An error has occured.'); } - - file_put_contents($basePath . DIRECTORY_SEPARATOR . 'sqldb.map', $sqlMap); } } diff --git a/Command/InsertSqlCommand.php b/Command/InsertSqlCommand.php index 4f0066d..348d46d 100644 --- a/Command/InsertSqlCommand.php +++ b/Command/InsertSqlCommand.php @@ -47,7 +47,7 @@ EOT 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'], @@ -55,7 +55,11 @@ EOT 'propel.schema.dir' => $this->getApplication()->getKernel()->getRootDir() . '/propel/schema/', )); - $output->writeln('All SQL statements have been executed.'); + if (true === $ret) { + $output->writeln('All SQL statements have been executed.'); + } else { + $output->writeln('WARNING ! An error has occured.'); + } } else { $output->writeln('You have to use --force to execute all SQL statements.'); } diff --git a/Command/PhingCommand.php b/Command/PhingCommand.php index e1c4eb5..854c053 100644 --- a/Command/PhingCommand.php +++ b/Command/PhingCommand.php @@ -126,7 +126,7 @@ abstract class PhingCommand extends Command $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 @@ abstract class PhingCommand extends Command // 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(); - $m = new Phing(); - $m->execute($args); - $m->runBuild(); + $phing = new Phing(); + $returnStatus = true; // optimistic way + + 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; } /**