Skip to content

Commit

Permalink
create sql folder if not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Virginie BARDALES committed Aug 23, 2012
1 parent b70c73f commit 89d2a43
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions Command/SqlBuildCommand.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
$filesystem->remove($cacheDir); $filesystem->remove($cacheDir);
$filesystem->mkdir($cacheDir); $filesystem->mkdir($cacheDir);


if (!$filesystem->exists($sqlDir)) {
$filesystem->mkdir($sqlDir);
}

// Execute the task // Execute the task
$ret = $this->callPhing('build-sql', array( $ret = $this->callPhing('build-sql', array(
'propel.sql.dir' => $cacheDir 'propel.sql.dir' => $cacheDir
Expand All @@ -77,10 +81,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
$fileExt = pathinfo($file->getFilename(), PATHINFO_EXTENSION); $fileExt = pathinfo($file->getFilename(), PATHINFO_EXTENSION);
$finalLocation = $sqlDir. DIRECTORY_SEPARATOR. $file->getFilename(); $finalLocation = $sqlDir. DIRECTORY_SEPARATOR. $file->getFilename();


if($fileExt === 'map' && $filesystem->exists($finalLocation)) { if ($fileExt === 'map' && $filesystem->exists($finalLocation)) {
$this->mergeMapFiles($finalLocation, (string) $file); $this->mergeMapFiles($finalLocation, (string) $file);
} } else {
else {
$filesystem->remove($finalLocation); $filesystem->remove($finalLocation);
$filesystem->rename((string) $file, $finalLocation); $filesystem->rename((string) $file, $finalLocation);
} }
Expand All @@ -105,18 +108,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
} }


/** /**
* Reads the existing target and the generated map files, and adds to the * Reads the existing target and the generated map files, and adds to the
* target the missing lines that are in the generated file. * target the missing lines that are in the generated file.
* *
* @param string $target target map filename * @param string $target target map filename
* @param string $generated generated map filename * @param string $generated generated map filename
* *
* @return boolean result * @return boolean result
*/ */
protected function mergeMapFiles($target, $generated) { protected function mergeMapFiles($target, $generated)
{
if(($targetContent = file($target)) === false) if(($targetContent = file($target)) === false)

return false; return false;
if(($generatedContent = file($generated)) === false) if(($generatedContent = file($generated)) === false)

return false; return false;


$targetContent = array_merge($generatedContent, array_diff($targetContent, $generatedContent)); $targetContent = array_merge($generatedContent, array_diff($targetContent, $generatedContent));
Expand Down

0 comments on commit 89d2a43

Please sign in to comment.