Skip to content

Commit bde72e0

Browse files
committed
Merge pull request propelorm#383 from havvg/1.5
generate SQL files into cache directory
2 parents 93dc571 + fe65d84 commit bde72e0

2 files changed

Lines changed: 14 additions & 30 deletions

File tree

Command/SqlBuildCommand.php

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@
77
*
88
* @license MIT License
99
*/
10-
1110
namespace Propel\PropelBundle\Command;
1211

1312
use Symfony\Component\Console\Input\InputInterface;
1413
use Symfony\Component\Console\Input\InputOption;
1514
use Symfony\Component\Console\Output\OutputInterface;
16-
use Symfony\Component\Console\Output\Output;
1715
use Symfony\Component\Filesystem\Filesystem;
1816
use Symfony\Component\Finder\Finder;
1917

20-
use Propel\PropelBundle\Command\AbstractCommand;
21-
2218
/**
2319
* SqlBuildCommand.
2420
*
@@ -55,41 +51,33 @@ protected function execute(InputInterface $input, OutputInterface $output)
5551
$finder = new Finder();
5652
$filesystem = new Filesystem();
5753

58-
$sqlDir = $this->getApplication()->getKernel()->getRootDir(). DIRECTORY_SEPARATOR . 'propel'. DIRECTORY_SEPARATOR . 'sql';
59-
$cacheDir = $this->getApplication()->getKernel()->getCacheDir(). DIRECTORY_SEPARATOR . 'sql';
54+
$sqlDir = $this->getApplication()->getKernel()->getCacheDir().DIRECTORY_SEPARATOR.'propel'.DIRECTORY_SEPARATOR.'sql';
6055

61-
$filesystem->remove($cacheDir);
62-
$filesystem->mkdir($cacheDir);
63-
64-
if (!$filesystem->exists($sqlDir)) {
65-
$filesystem->mkdir($sqlDir);
66-
}
56+
$filesystem->remove($sqlDir);
57+
$filesystem->mkdir($sqlDir);
6758

6859
// Execute the task
6960
$ret = $this->callPhing('build-sql', array(
70-
'propel.sql.dir' => $cacheDir
61+
'propel.sql.dir' => $sqlDir,
7162
));
7263

7364
// Show the list of generated files
7465
if (true === $ret) {
75-
$files = $finder->name('*')->in($cacheDir);
66+
$files = $finder->name('*')->in($sqlDir);
7667

7768
$nbFiles = 0;
7869
foreach ($files as $file) {
7970
$fileExt = pathinfo($file->getFilename(), PATHINFO_EXTENSION);
80-
$finalLocation = $sqlDir. DIRECTORY_SEPARATOR. $file->getFilename();
71+
$finalLocation = $sqlDir.DIRECTORY_SEPARATOR.$file->getFilename();
8172

8273
if ($fileExt === 'map' && $filesystem->exists($finalLocation)) {
8374
$this->mergeMapFiles($finalLocation, (string) $file);
84-
} else {
85-
$filesystem->remove($finalLocation);
86-
$filesystem->rename((string) $file, $finalLocation);
8775
}
8876

8977
$this->writeNewFile($output, (string) $file);
9078

9179
if ('sql' === $fileExt) {
92-
$nbFiles++;
80+
++$nbFiles;
9381
}
9482
}
9583

@@ -100,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
10088
$this->writeSection($output, array(
10189
'[Propel] Error',
10290
'',
103-
'An error has occured during the "propel:sql:build" command process. To get more details, run the command with the "--verbose" option.'
91+
'An error has occured during the "propel:sql:build" command process. To get more details, run the command with the "--verbose" option.',
10492
), 'fg=white;bg=red');
10593
}
10694
}
@@ -112,16 +100,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
112100
* @param string $target target map filename
113101
* @param string $generated generated map filename
114102
*
115-
* @return boolean result
103+
* @return bool
116104
*/
117105
protected function mergeMapFiles($target, $generated)
118106
{
119-
if(($targetContent = file($target)) === false)
120-
107+
if (false === ($targetContent = file($target))) {
121108
return false;
122-
if(($generatedContent = file($generated)) === false)
109+
}
123110

111+
if (false === ($generatedContent = file($generated))) {
124112
return false;
113+
}
125114

126115
$targetContent = array_merge($generatedContent, array_diff($targetContent, $generatedContent));
127116

Command/SqlInsertCommand.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
*
88
* @license MIT License
99
*/
10-
1110
namespace Propel\PropelBundle\Command;
1211

13-
use Propel\PropelBundle\Command\AbstractCommand;
1412
use Symfony\Component\Console\Input\InputInterface;
1513
use Symfony\Component\Console\Input\InputOption;
1614
use Symfony\Component\Console\Output\OutputInterface;
@@ -52,9 +50,6 @@ protected function configure()
5250
*/
5351
protected function execute(InputInterface $input, OutputInterface $output)
5452
{
55-
// Bad require but needed :(
56-
require_once $this->getContainer()->getParameter('propel.path') . '/generator/lib/util/PropelSqlManager.php';
57-
5853
if ($input->getOption('force')) {
5954
$connections = $this->getConnections();
6055
$sqlDir = $this->getSqlDir();
@@ -80,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8075

8176
protected function getSqlDir()
8277
{
83-
return sprintf('%s/propel/sql', $this->getApplication()->getKernel()->getRootDir());
78+
return sprintf('%s/propel/sql', $this->getApplication()->getKernel()->getCacheDir());
8479
}
8580

8681
/**

0 commit comments

Comments
 (0)