Skip to content

Commit

Permalink
[FrameworkBundle] added feedback in cache:clear
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmyio authored and fabpot committed Jan 7, 2014
1 parent 0af3ca3 commit a1f6411
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php
Expand Up @@ -66,7 +66,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$kernel = $this->getContainer()->get('kernel');
$output->writeln(sprintf('Clearing the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
$output->writeln($this->getClearingCacheMessage($output, $kernel));

$this->getContainer()->get('cache_clearer')->clear($realCacheDir);

if ($input->getOption('no-warmup')) {
Expand All @@ -77,19 +78,53 @@ protected function execute(InputInterface $input, OutputInterface $output)
$warmupDir = substr($realCacheDir, 0, -1).'_';

if ($filesystem->exists($warmupDir)) {
$this->writelnIfVerbose($output, 'Clearing outdated warmup directory...');
$filesystem->remove($warmupDir);
}

$this->writelnIfVerbose($output, 'Warming up cache...');
$this->warmup($warmupDir, $realCacheDir, !$input->getOption('no-optional-warmers'));

$filesystem->rename($realCacheDir, $oldCacheDir);
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
sleep(1); // workaround for Windows PHP rename bug
}
$filesystem->rename($warmupDir, $realCacheDir);
$this->writelnIfVerbose($output, 'Warm up completed...');
}

$this->writelnIfVerbose($output, 'Removing old cache directory...');
$filesystem->remove($oldCacheDir);
$this->writelnIfVerbose($output, 'Completed clearing cache' . ($input->getOption('no-warmup') ? "!" : " and warmup!"));
}

/**
* @param OutputInterface $output
* @param KernelInterface $kernel
* @return string
*/
protected function getClearingCacheMessage(OutputInterface $output, KernelInterface $kernel){
$message = 'Clearing the cache for the <info>%s</info> environment with debug <info>%s</info>';
$message .= $this->isVerbose($output) ? ":" : "";
return sprintf($message, $kernel->getEnvironment(), var_export($kernel->isDebug(), true));
}

/**
* @param OutputInterface $output
* @param string $message
*/
protected function writelnIfVerbose(OutputInterface $output, $message){
if ($this->isVerbose($output)){
$output->writeln($message);
}
}

/**
* @param OutputInterface $output
* @return bool
*/
protected function isVerbose(OutputInterface $output){
return OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity();
}

/**
Expand Down

0 comments on commit a1f6411

Please sign in to comment.