From 42c98921a2da7daa7eef78c73ce8674505b5d4b4 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Wed, 8 Feb 2012 19:44:27 -0500 Subject: [PATCH] [FrameworkBundle] Allow cache:clear/warmup to skip optional warmers --- .../FrameworkBundle/Command/CacheClearCommand.php | 11 ++++++++--- .../FrameworkBundle/Command/CacheWarmupCommand.php | 10 +++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php index 172a157d2e..fdce7084f2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php @@ -36,6 +36,7 @@ class CacheClearCommand extends ContainerAwareCommand ->setName('cache:clear') ->setDefinition(array( new InputOption('no-warmup', '', InputOption::VALUE_NONE, 'Do not warm up the cache'), + new InputOption('no-optional-warmers', '', InputOption::VALUE_NONE, 'Skip optional cache warmers (faster)'), )) ->setDescription('Clears the cache') ->setHelp(<<warmup($warmupDir); + $this->warmup($warmupDir, !$input->getOption('no-optional-warmers')); rename($realCacheDir, $oldCacheDir); rename($warmupDir, $realCacheDir); @@ -80,7 +81,7 @@ EOF $this->getContainer()->get('filesystem')->remove($oldCacheDir); } - protected function warmup($warmupDir) + protected function warmup($warmupDir, $enableOptionalWarmers = true) { $this->getContainer()->get('filesystem')->remove($warmupDir); @@ -96,7 +97,11 @@ EOF $kernel->boot(); $warmer = $kernel->getContainer()->get('cache_warmer'); - $warmer->enableOptionalWarmers(); + + if ($enableOptionalWarmers) { + $warmer->enableOptionalWarmers(); + } + $warmer->warmUp($warmupDir); // fix container files and classes diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php index 0b4bd56f63..1c2ba0e790 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php @@ -12,6 +12,7 @@ namespace Symfony\Bundle\FrameworkBundle\Command; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; /** @@ -28,6 +29,9 @@ class CacheWarmupCommand extends ContainerAwareCommand { $this ->setName('cache:warmup') + ->setDefinition(array( + new InputOption('no-optional-warmers', '', InputOption::VALUE_NONE, 'Skip optional cache warmers (faster)'), + )) ->setDescription('Warms up an empty cache') ->setHelp(<<cache:warmup command warms up the cache. @@ -47,7 +51,11 @@ EOF $output->writeln(sprintf('Warming up the cache for the %s environment with debug %s', $kernel->getEnvironment(), var_export($kernel->isDebug(), true))); $warmer = $this->getContainer()->get('cache_warmer'); - $warmer->enableOptionalWarmers(); + + if (!$input->getOption('no-optional-warmers')) { + $warmer->enableOptionalWarmers(); + } + $warmer->warmUp($this->getContainer()->getParameter('kernel.cache_dir')); } }