From ef550f5854b5f4d9818cf06d0b025ca71ad5d09a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Mon, 4 Mar 2013 17:52:53 +0100 Subject: [PATCH 1/2] [FrameworkBundle] added directory checks & filesystem usage --- .../Command/CacheClearCommand.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php index a9aa7a5b8f6fc..b65282f94aa09 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php @@ -14,6 +14,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Finder\Finder; @@ -62,23 +63,32 @@ protected function execute(InputInterface $input, OutputInterface $output) 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 %s environment with debug %s', $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) From 55032fe3fa68d72d4f4d0bbb03d6a4276cf7c1af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Mon, 4 Mar 2013 18:02:07 +0100 Subject: [PATCH 2/2] [FrameworkBundle] removed unused use statement --- src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php index b65282f94aa09..358ce4d31e7a4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php @@ -14,7 +14,6 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Finder\Finder;