Permalink
Browse files

[FrameworkBundle] added --without-debug option to cache:clear as the …

…debug flag value can be different from the one used for the command execution (think generating the prod cache but still with debug information when running the command)
  • Loading branch information...
1 parent e4a636a commit 85778caba16ad6830fdc28eaa6ee8c1e91d009ef @fabpot fabpot committed Mar 21, 2011
Showing with 13 additions and 10 deletions.
  1. +13 −10 src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php
View
23 src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php
@@ -33,13 +33,16 @@ protected function configure()
$this
->setName('cache:clear')
->setDefinition(array(
- new InputOption('no-warmup', '', InputOption::VALUE_NONE, 'Do not warm up the cache')
+ new InputOption('no-warmup', '', InputOption::VALUE_NONE, 'Do not warm up the cache'),
+ new InputOption('without-debug', '', InputOption::VALUE_NONE, 'If the cache is warmed up, whether to disable debugging or not'),
@ubermuda
ubermuda Mar 21, 2011

why not "no-debug" to be consistent with "no-warmup" ?

@stof
stof Mar 21, 2011

Because no-debug is still used by the console itself to boot the kernel without the debug mode to run the command

@ubermuda
ubermuda Mar 21, 2011

what about no-warmup-debug then?

))
->setDescription('Clear the cache')
->setHelp(<<<EOF
-The <info>cache:clear</info> command clears the application cache for the current environment:
+The <info>cache:clear</info> command clears the application cache for a given environment
+and debug mode:
-<info>./app/console cache:clear</info>
+<info>./app/console cache:clear dev</info>
+<info>./app/console cache:clear prod --without-debug</info>
EOF
)
;
@@ -54,15 +57,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
$oldCacheDir = $realCacheDir.'_old';
if (!is_writable($realCacheDir)) {
- throw new \RuntimeException(sprintf('Unable to write in "%s" directory', $this->realCacheDir));
+ throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $this->realCacheDir));
}
if ($input->getOption('no-warmup')) {
rename($realCacheDir, $oldCacheDir);
} else {
$warmupDir = $realCacheDir.'_new';
- $this->warmup($warmupDir);
+ $this->warmup(!$input->getOption('without-debug'), $warmupDir);
rename($realCacheDir, $oldCacheDir);
rename($warmupDir, $realCacheDir);
@@ -71,18 +74,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->container->get('filesystem')->remove($oldCacheDir);
}
- protected function warmup($warmupDir)
+ protected function warmup($debug, $warmupDir)
{
$this->container->get('filesystem')->remove($warmupDir);
- $kernel = $this->getTempKernel($this->container->get('kernel'), $warmupDir);
+ $kernel = $this->getTempKernel($this->container->get('kernel'), $debug, $warmupDir);
$kernel->boot();
$warmer = $kernel->getContainer()->get('cache_warmer');
$warmer->enableOptionalWarmers();
$warmer->warmUp($warmupDir);
- // rename container files
+ // fix container files and classes
$finder = new Finder();
foreach ($finder->files()->name(get_class($kernel->getContainer()).'*')->in($warmupDir) as $file) {
$content = file_get_contents($file);
@@ -92,7 +95,7 @@ protected function warmup($warmupDir)
}
}
- protected function getTempKernel(KernelInterface $parent, $warmupDir)
+ protected function getTempKernel(KernelInterface $parent, $debug, $warmupDir)
{
$parentClass = get_class($parent);
$rand = uniqid();
@@ -124,6 +127,6 @@ protected function getContainerClass()
require_once $file;
@unlink($file);
- return new $class($parent->getEnvironment(), $parent->isDebug());
+ return new $class($parent->getEnvironment(), $debug);
}
}

1 comment on commit 85778ca

@beberlei

How about adding flags for user, group and filesystem rights to recursively apply to the new cache folder? These differ on many systems on cli vs web.

Please sign in to comment.