sql:build take existing files into account
Signed-off-by: Martin Richard <martius@martiusweb.net>
This commit is contained in:
parent
4980f54b6e
commit
54c60cf4a1
1 changed files with 38 additions and 5 deletions
|
|
@ -58,23 +58,36 @@ EOT
|
|||
$filesystem = new Filesystem();
|
||||
|
||||
$sqlDir = $this->getApplication()->getKernel()->getRootDir(). DIRECTORY_SEPARATOR . 'propel'. DIRECTORY_SEPARATOR . 'sql';
|
||||
$cacheDir = $this->getApplication()->getKernel()->getCacheDir(). DIRECTORY_SEPARATOR . 'sql';
|
||||
|
||||
$filesystem->remove($sqlDir);
|
||||
$filesystem->mkdir($sqlDir);
|
||||
$filesystem->remove($cacheDir);
|
||||
$filesystem->mkdir($cacheDir);
|
||||
|
||||
// Execute the task
|
||||
$ret = $this->callPhing('build-sql', array(
|
||||
'propel.sql.dir' => $sqlDir
|
||||
'propel.sql.dir' => $cacheDir
|
||||
));
|
||||
|
||||
// Show the list of generated files
|
||||
if (true === $ret) {
|
||||
$files = $finder->name('*')->in($sqlDir);
|
||||
$files = $finder->name('*')->in($cacheDir);
|
||||
|
||||
$nbFiles = 0;
|
||||
foreach ($files as $file) {
|
||||
$fileExt = pathinfo($file->getFilename(), PATHINFO_EXTENSION);
|
||||
$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' === pathinfo($file->getFilename(), PATHINFO_EXTENSION)) {
|
||||
if ('sql' === $fileExt) {
|
||||
$nbFiles++;
|
||||
}
|
||||
}
|
||||
|
|
@ -90,4 +103,24 @@ EOT
|
|||
), 'fg=white;bg=red');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the existing target and the generated map files, and adds to the
|
||||
* target the missing lines that are in the generated file.
|
||||
*
|
||||
* @param string $target target map filename
|
||||
* @param string $generated generated map filename
|
||||
*
|
||||
* @return boolean result
|
||||
*/
|
||||
protected function mergeMapFiles($target, $generated) {
|
||||
if(($targetContent = file($target)) === false)
|
||||
return false;
|
||||
if(($generatedContent = file($generated)) === false)
|
||||
return false;
|
||||
|
||||
$targetContent = array_merge($generatedContent, array_diff($targetContent, $generatedContent));
|
||||
|
||||
return file_put_contents($target, $targetContent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue