diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php index 7c7c172552..b60e7dff65 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php @@ -63,13 +63,10 @@ EOF throw new \RuntimeException(sprintf('Unable to write %s directory', $this->realCacheDir)); } - $this->clearDir($oldCacheDir); - if (!$input->getOption('warmup')) { $output->writeln('Clear cache'); rename($realCacheDir, $oldCacheDir); - $this->clearDir($oldCacheDir); } else { parent::execute($input, $output); @@ -78,7 +75,8 @@ EOF rename($this->kernelTmp->getCacheDir(), $realCacheDir); $output->writeln('Clear the old cache'); - $this->clearDir($oldCacheDir); } + + $this->container->get('filesystem')->remove($oldCacheDir); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php index f4b657f2ed..d7d2701fa2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php @@ -73,7 +73,7 @@ EOF $this->cacheDir ); - $this->clearDir($this->kernelTmp->getCacheDir()); + $this->container->get('filesystem')->remove($this->kernelTmp->getCacheDir()); $this->kernelTmp->boot(); unlink($this->kernelTmp->getCacheDir().DIRECTORY_SEPARATOR.$this->kernelTmp->getContainerClass().'.php'); @@ -88,39 +88,4 @@ EOF $warmer->enableOptionalWarmers(); $warmer->warmUp($container->getParameter('kernel.cache_dir')); } - - protected function clearDir($dir) - { - if (is_dir($dir)) { - $finder = new Finder(); - $files = $finder - ->in($dir) - ->getIterator() - ; - - $array = iterator_to_array($files); - - foreach (array_reverse($array) as $file) { - if ($file->isFile()) { - if (!is_writable($file->getPathname())) { - throw new \RuntimeException(sprintf('Unable to delete %s file', $file->getPathname())); - } - - unlink($file->getPathname()); - } else { - if (!is_writable($file->getPathname())) { - throw new \RuntimeException(sprintf('Unable to delete %s directory', $file->getPathname())); - } - - rmdir($file->getPathname()); - } - } - - if (!is_writable($dir)) { - throw new \RuntimeException(sprintf('Unable to delete %s directory', $dir)); - } - - rmdir($dir); - } - } }