1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace As3\Bundle\ModlrBundle\Command\Metadata; |
4
|
|
|
|
5
|
|
|
use As3\Modlr\Metadata\Cache\CacheWarmer; |
6
|
|
|
use Symfony\Component\Console\Command\Command; |
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Clears/warms the metadata cache. |
14
|
|
|
* |
15
|
|
|
* @author Jacob Bare <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class ClearCacheCommand extends Command |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var CacheWarmer |
21
|
|
|
*/ |
22
|
|
|
private $cacheWarmer; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Constructor. |
26
|
|
|
* |
27
|
|
|
* @param CacheWarmer $cacheWarmer |
28
|
|
|
*/ |
29
|
|
|
public function __construct(CacheWarmer $cacheWarmer) |
30
|
|
|
{ |
31
|
|
|
parent::__construct(); |
32
|
|
|
$this->cacheWarmer = $cacheWarmer; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
|
|
protected function configure() |
39
|
|
|
{ |
40
|
|
|
$this |
41
|
|
|
->setName('as3:modlr:metadata:cache:clear') |
42
|
|
|
->setDescription('Clears/warms metadata for all models, or for a specific model.') |
43
|
|
|
->addArgument('type', InputArgument::OPTIONAL, 'Specify the model type to clear.') |
44
|
|
|
->addOption('no-warm', null, InputOption::VALUE_NONE, 'If set, warming will be disabled.') |
45
|
|
|
; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
*/ |
51
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
52
|
|
|
{ |
53
|
|
|
$type = $input->getArgument('type') ?: null; |
54
|
|
|
$noWarm = $input->getOption('no-warm'); |
55
|
|
|
|
56
|
|
|
$action = (true === $noWarm) ? 'Clearing' : 'Warming'; |
57
|
|
|
$types = (null === $type) ? 'all types' : sprintf('model type "%s"', $type); |
58
|
|
|
|
59
|
|
|
$output->writeln(sprintf('<info>%s the metadata cache for %s</info>', $action, $types)); |
60
|
|
|
|
61
|
|
|
$result = (true === $noWarm) ? $this->cacheWarmer->clear($type) : $this->cacheWarmer->warm($type); |
62
|
|
|
|
63
|
|
|
$output->writeln(sprintf('<info>Action complete for: %s</info>', implode(', ', $result))); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|