[command] Fixed output (for real)
This commit is contained in:
parent
e35ae76511
commit
f18df260fe
7 changed files with 50 additions and 35 deletions
|
|
@ -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 <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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <info>%s</info> in <comment>%s</comment>.',
|
||||
$schemaDetails['bundle'],
|
||||
$targetSqlFilePath)
|
||||
);
|
||||
}
|
||||
|
||||
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',
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ EOT
|
|||
$output->writeln('No dumped files.');
|
||||
}
|
||||
} else {
|
||||
$this->writeTaskError('datadump', false);
|
||||
$this->writeTaskError($output, 'datadump', false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ EOT
|
|||
$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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ EOT
|
|||
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>');
|
||||
|
|
|
|||
|
|
@ -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('<info>[Propel] All SQL statements have been executed.</info>');
|
||||
} else {
|
||||
$this->writeTaskError('insert-sql', false);
|
||||
$this->writeTaskError($output, 'insert-sql', false);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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('>> <info>File+</info> ' . $filename);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue