Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #171 from Martiusweb/build_sql_update

sql:build take existing files into account
  • Loading branch information...
commit b70c73f674ad9c1d68ad24f83d8b5dec4f5f008c 2 parents abf90dd + 54c60cf
@willdurand willdurand authored
Showing with 38 additions and 5 deletions.
  1. +38 −5 Command/SqlBuildCommand.php
View
43 Command/SqlBuildCommand.php
@@ -58,23 +58,36 @@ protected function execute(InputInterface $input, OutputInterface $output)
$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 @@ protected function execute(InputInterface $input, OutputInterface $output)
), '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);
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.