[FrameworkBundle] avoids cache:clear to break if new/old folders already exist

This commit is contained in:
Jean-François Simon 2013-03-04 17:52:53 +01:00 committed by Fabien Potencier
parent 0e7b5fb3bb
commit 1d3da29779

View File

@ -62,23 +62,32 @@ EOF
throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $realCacheDir));
}
$filesystem = $this->getContainer()->get('filesystem');
$kernel = $this->getContainer()->get('kernel');
$output->writeln(sprintf('Clearing the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
$this->getContainer()->get('cache_clearer')->clear($realCacheDir);
if ($filesystem->exists($oldCacheDir)) {
$filesystem->remove($oldCacheDir);
}
if ($input->getOption('no-warmup')) {
rename($realCacheDir, $oldCacheDir);
$filesystem->rename($realCacheDir, $oldCacheDir);
} else {
$warmupDir = $realCacheDir.'_new';
if ($filesystem->exists($warmupDir)) {
$filesystem->remove($warmupDir);
}
$this->warmup($warmupDir, !$input->getOption('no-optional-warmers'));
rename($realCacheDir, $oldCacheDir);
rename($warmupDir, $realCacheDir);
$filesystem->rename($realCacheDir, $oldCacheDir);
$filesystem->rename($warmupDir, $realCacheDir);
}
$this->getContainer()->get('filesystem')->remove($oldCacheDir);
$filesystem->remove($oldCacheDir);
}
protected function warmup($warmupDir, $enableOptionalWarmers = true)