5 * Contains \Drupal\Console\Command\Cache\RebuildCommand.
8 namespace Drupal\Console\Command\Cache;
10 use Drupal\Console\Core\Command\Command;
11 use Drupal\Console\Utils\DrupalApi;
12 use Drupal\Console\Utils\Site;
13 use Symfony\Component\Console\Input\InputArgument;
14 use Symfony\Component\Console\Input\InputInterface;
15 use Symfony\Component\Console\Output\OutputInterface;
16 use Symfony\Component\HttpFoundation\RequestStack;
19 * Class RebuildCommand
21 * @package Drupal\Console\Command\Cache
23 class RebuildCommand extends Command
35 protected $classLoader;
40 protected $requestStack;
43 * RebuildCommand constructor.
45 * @param DrupalApi $drupalApi
48 * @param RequestStack $requestStack
50 public function __construct(
54 RequestStack $requestStack
56 $this->drupalApi = $drupalApi;
58 $this->classLoader = $classLoader;
59 $this->requestStack = $requestStack;
60 parent::__construct();
66 protected function configure()
69 ->setName('cache:rebuild')
70 ->setDescription($this->trans('commands.cache.rebuild.description'))
73 InputArgument::OPTIONAL,
74 $this->trans('commands.cache.rebuild.options.cache')
75 )->setAliases(['cr']);
81 protected function execute(InputInterface $input, OutputInterface $output)
83 $cache = $input->getArgument('cache')?:'all';
84 $this->site->loadLegacyFile('/core/includes/utility.inc');
86 if ($cache && !$this->drupalApi->isValidCache($cache)) {
87 $this->getIo()->error(
89 $this->trans('commands.cache.rebuild.messages.invalid-cache'),
97 $this->getIo()->newLine();
98 $this->getIo()->comment($this->trans('commands.cache.rebuild.messages.rebuild'));
100 if ($cache === 'all') {
101 $this->drupalApi->drupal_rebuild(
103 $this->requestStack->getCurrentRequest()
106 $caches = $this->drupalApi->getCaches();
107 $caches[$cache]->deleteAll();
110 $this->getIo()->success($this->trans('commands.cache.rebuild.messages.completed'));
118 protected function interact(InputInterface $input, OutputInterface $output)
120 $cache = $input->getArgument('cache');
122 $cacheKeys = array_keys($this->drupalApi->getCaches());
124 $cache = $this->getIo()->choiceNoList(
125 $this->trans('commands.cache.rebuild.questions.cache'),
130 $input->setArgument('cache', $cache);