Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config/services/cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ services:
arguments: ['@console.drupal_api', '@console.site', '@class_loader', '@request_stack']
tags:
- { name: drupal.command }
console.cache_tag_invalidate:
class: Drupal\Console\Command\Cache\TagInvalidateCommand
arguments: ['@cache_tags.invalidator']
tags:
- { name: drupal.command }
72 changes: 72 additions & 0 deletions src/Command/Cache/TagInvalidateCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

/**
* @file
* Contains \Drupal\Console\Command\Cache\TagInvalidateCommand.
*/

namespace Drupal\Console\Command\Cache;

use Drupal\Console\Core\Command\Shared\CommandTrait;
use Drupal\Console\Core\Style\DrupalStyle;
use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class TagInvalidateCommand extends Command
{
use CommandTrait;

/**
* @var CacheTagsInvalidatorInterface
*/
protected $invalidator;

/**
* TagInvalidateCommand constructor.
*
* @param CacheTagsInvalidatorInterface $invalidator
*/
public function __construct(CacheTagsInvalidatorInterface $invalidator)
{
parent::__construct();
$this->invalidator = $invalidator;
}

/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('cache:tag:invalidate')
->setDescription($this->trans('commands.cache.tag.invalidate.description'))
->addArgument(
'tag',
InputArgument::REQUIRED | InputArgument::IS_ARRAY,
$this->trans('commands.cache.tag.invalidate.options.tag')
)
->setAliases(['cti']);
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$tags = $input->getArgument('tag');

$io->comment(
sprintf(
$this->trans('commands.cache.tag.invalidate.messages.start'),
implode(', ', $tags)
)
);

$this->invalidator->invalidateTags($tags);
$io->success($this->trans('commands.cache.tag.invalidate.messages.completed'));
}
}