Merge pull request #383 from havvg/1.5

generate SQL files into cache directory
This commit is contained in:
Toni Uebernickel 2016-01-23 15:00:50 +01:00
commit bde72e0ee6
2 changed files with 14 additions and 30 deletions

View file

@ -7,18 +7,14 @@
*
* @license MIT License
*/
namespace Propel\PropelBundle\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\Output;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Propel\PropelBundle\Command\AbstractCommand;
/**
* SqlBuildCommand.
*
@ -55,41 +51,33 @@ EOT
$finder = new Finder();
$filesystem = new Filesystem();
$sqlDir = $this->getApplication()->getKernel()->getRootDir(). DIRECTORY_SEPARATOR . 'propel'. DIRECTORY_SEPARATOR . 'sql';
$cacheDir = $this->getApplication()->getKernel()->getCacheDir(). DIRECTORY_SEPARATOR . 'sql';
$sqlDir = $this->getApplication()->getKernel()->getCacheDir().DIRECTORY_SEPARATOR.'propel'.DIRECTORY_SEPARATOR.'sql';
$filesystem->remove($cacheDir);
$filesystem->mkdir($cacheDir);
if (!$filesystem->exists($sqlDir)) {
$filesystem->mkdir($sqlDir);
}
$filesystem->remove($sqlDir);
$filesystem->mkdir($sqlDir);
// Execute the task
$ret = $this->callPhing('build-sql', array(
'propel.sql.dir' => $cacheDir
'propel.sql.dir' => $sqlDir,
));
// Show the list of generated files
if (true === $ret) {
$files = $finder->name('*')->in($cacheDir);
$files = $finder->name('*')->in($sqlDir);
$nbFiles = 0;
foreach ($files as $file) {
$fileExt = pathinfo($file->getFilename(), PATHINFO_EXTENSION);
$finalLocation = $sqlDir. DIRECTORY_SEPARATOR. $file->getFilename();
$finalLocation = $sqlDir.DIRECTORY_SEPARATOR.$file->getFilename();
if ($fileExt === 'map' && $filesystem->exists($finalLocation)) {
$this->mergeMapFiles($finalLocation, (string) $file);
} else {
$filesystem->remove($finalLocation);
$filesystem->rename((string) $file, $finalLocation);
}
$this->writeNewFile($output, (string) $file);
if ('sql' === $fileExt) {
$nbFiles++;
++$nbFiles;
}
}
@ -100,7 +88,7 @@ EOT
$this->writeSection($output, array(
'[Propel] Error',
'',
'An error has occured during the "propel:sql:build" command process. To get more details, run the command with the "--verbose" option.'
'An error has occured during the "propel:sql:build" command process. To get more details, run the command with the "--verbose" option.',
), 'fg=white;bg=red');
}
}
@ -112,16 +100,17 @@ EOT
* @param string $target target map filename
* @param string $generated generated map filename
*
* @return boolean result
* @return bool
*/
protected function mergeMapFiles($target, $generated)
{
if(($targetContent = file($target)) === false)
if (false === ($targetContent = file($target))) {
return false;
if(($generatedContent = file($generated)) === false)
}
if (false === ($generatedContent = file($generated))) {
return false;
}
$targetContent = array_merge($generatedContent, array_diff($targetContent, $generatedContent));

View file

@ -7,10 +7,8 @@
*
* @license MIT License
*/
namespace Propel\PropelBundle\Command;
use Propel\PropelBundle\Command\AbstractCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
@ -52,9 +50,6 @@ EOT
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
// Bad require but needed :(
require_once $this->getContainer()->getParameter('propel.path') . '/generator/lib/util/PropelSqlManager.php';
if ($input->getOption('force')) {
$connections = $this->getConnections();
$sqlDir = $this->getSqlDir();
@ -80,7 +75,7 @@ EOT
protected function getSqlDir()
{
return sprintf('%s/propel/sql', $this->getApplication()->getKernel()->getRootDir());
return sprintf('%s/propel/sql', $this->getApplication()->getKernel()->getCacheDir());
}
/**