Skip to content

Commit

Permalink
[FrameworkBundle] added --without-debug option to cache:clear as the …
Browse files Browse the repository at this point in the history
…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
fabpot committed Mar 21, 2011
1 parent e4a636a commit 85778ca
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php
Expand Up @@ -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'),
))
->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
)
;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 85778ca

Please sign in to comment.