Skip to content

Commit a10fcb2

Browse files
cburschkajmolivas
authored andcommitted
Add cache:tag:invalidate command. (#3445)
1 parent f6091a9 commit a10fcb2

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

config/services/cache.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ services:
44
arguments: ['@console.drupal_api', '@console.site', '@class_loader', '@request_stack']
55
tags:
66
- { name: drupal.command }
7+
console.cache_tag_invalidate:
8+
class: Drupal\Console\Command\Cache\TagInvalidateCommand
9+
arguments: ['@cache_tags.invalidator']
10+
tags:
11+
- { name: drupal.command }
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Contains \Drupal\Console\Command\Cache\TagInvalidateCommand.
6+
*/
7+
8+
namespace Drupal\Console\Command\Cache;
9+
10+
use Drupal\Console\Core\Command\Shared\CommandTrait;
11+
use Drupal\Console\Core\Style\DrupalStyle;
12+
use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
13+
use Symfony\Component\Console\Command\Command;
14+
use Symfony\Component\Console\Input\InputArgument;
15+
use Symfony\Component\Console\Input\InputInterface;
16+
use Symfony\Component\Console\Output\OutputInterface;
17+
18+
class TagInvalidateCommand extends Command
19+
{
20+
use CommandTrait;
21+
22+
/**
23+
* @var CacheTagsInvalidatorInterface
24+
*/
25+
protected $invalidator;
26+
27+
/**
28+
* TagInvalidateCommand constructor.
29+
*
30+
* @param CacheTagsInvalidatorInterface $invalidator
31+
*/
32+
public function __construct(CacheTagsInvalidatorInterface $invalidator)
33+
{
34+
parent::__construct();
35+
$this->invalidator = $invalidator;
36+
}
37+
38+
/**
39+
* {@inheritdoc}
40+
*/
41+
protected function configure()
42+
{
43+
$this
44+
->setName('cache:tag:invalidate')
45+
->setDescription($this->trans('commands.cache.tag.invalidate.description'))
46+
->addArgument(
47+
'tag',
48+
InputArgument::REQUIRED | InputArgument::IS_ARRAY,
49+
$this->trans('commands.cache.tag.invalidate.options.tag')
50+
)
51+
->setAliases(['cti']);
52+
}
53+
54+
/**
55+
* {@inheritdoc}
56+
*/
57+
protected function execute(InputInterface $input, OutputInterface $output)
58+
{
59+
$io = new DrupalStyle($input, $output);
60+
$tags = $input->getArgument('tag');
61+
62+
$io->comment(
63+
sprintf(
64+
$this->trans('commands.cache.tag.invalidate.messages.start'),
65+
implode(', ', $tags)
66+
)
67+
);
68+
69+
$this->invalidator->invalidateTags($tags);
70+
$io->success($this->trans('commands.cache.tag.invalidate.messages.completed'));
71+
}
72+
}

0 commit comments

Comments
 (0)