2011-01-24 10:16:22 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2011-01-24 10:16:22 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Symfony\Bundle\FrameworkBundle\Command;
|
|
|
|
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
2011-03-11 22:35:48 +00:00
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
2011-01-24 10:16:22 +00:00
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2011-03-11 22:35:48 +00:00
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
|
|
use Symfony\Component\Finder\Finder;
|
2011-01-24 10:16:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Warmup the cache.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
2011-03-11 22:35:48 +00:00
|
|
|
* @author Francis Besset <francis.besset@gmail.com>
|
2011-01-24 10:16:22 +00:00
|
|
|
*/
|
|
|
|
class CacheWarmupCommand extends Command
|
|
|
|
{
|
2011-03-11 22:35:48 +00:00
|
|
|
protected $cacheDir;
|
|
|
|
protected $kernelTmp;
|
|
|
|
|
2011-01-24 10:16:22 +00:00
|
|
|
/**
|
|
|
|
* @see Command
|
|
|
|
*/
|
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$this
|
|
|
|
->setName('cache:warmup')
|
|
|
|
->setDescription('Warms up an empty cache')
|
2011-03-11 22:35:48 +00:00
|
|
|
->setDefinition(array(
|
|
|
|
new InputOption('warmup-dir', '', InputOption::VALUE_OPTIONAL, 'Warms up the cache in a specific directory')
|
|
|
|
))
|
2011-01-24 10:16:22 +00:00
|
|
|
->setHelp(<<<EOF
|
2011-03-11 22:35:48 +00:00
|
|
|
The <info>cache:warmup --warmup-dir=new_cache</info> command warms up the cache.
|
2011-01-24 10:16:22 +00:00
|
|
|
|
2011-03-11 22:35:48 +00:00
|
|
|
Before running this command, the cache must be empty if not use warmup-dir option.
|
2011-01-24 10:16:22 +00:00
|
|
|
EOF
|
|
|
|
)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2011-03-11 22:35:48 +00:00
|
|
|
protected function initialize(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
|
|
|
parent::initialize($input, $output);
|
|
|
|
|
|
|
|
if ($input->hasOption('warmup-dir')) {
|
|
|
|
$this->cacheDir = $input->getOption('warmup-dir');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-24 10:16:22 +00:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
|
|
|
$output->writeln('Warming up the cache');
|
|
|
|
|
2011-03-11 22:35:48 +00:00
|
|
|
if (!$this->cacheDir) {
|
|
|
|
$this->warmUp($this->container);
|
|
|
|
} else {
|
2011-03-21 08:33:58 +00:00
|
|
|
$class = get_class($this->container->get('kernel'));
|
|
|
|
$this->kernelTmp = new $class(
|
2011-03-11 22:35:48 +00:00
|
|
|
$this->container->getParameter('kernel.environment'),
|
|
|
|
$this->container->getParameter('kernel.debug'),
|
|
|
|
$this->cacheDir
|
|
|
|
);
|
|
|
|
|
2011-03-21 08:31:04 +00:00
|
|
|
$this->container->get('filesystem')->remove($this->kernelTmp->getCacheDir());
|
2011-03-11 22:35:48 +00:00
|
|
|
|
|
|
|
$this->kernelTmp->boot();
|
|
|
|
unlink($this->kernelTmp->getCacheDir().DIRECTORY_SEPARATOR.$this->kernelTmp->getContainerClass().'.php');
|
|
|
|
|
|
|
|
$this->warmUp($this->kernelTmp->getContainer());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function warmUp(ContainerInterface $container)
|
|
|
|
{
|
|
|
|
$warmer = $container->get('cache_warmer');
|
2011-01-24 10:16:22 +00:00
|
|
|
$warmer->enableOptionalWarmers();
|
2011-03-11 22:35:48 +00:00
|
|
|
$warmer->warmUp($container->getParameter('kernel.cache_dir'));
|
|
|
|
}
|
2011-01-24 10:16:22 +00:00
|
|
|
}
|