5 * Contains \Drupal\Console\Command\Cache\RebuildCommand.
8 namespace Drupal\Console\Command\Cache;
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Symfony\Component\HttpFoundation\RequestStack;
14 use Symfony\Component\Console\Command\Command;
15 use Drupal\Console\Core\Command\Shared\CommandTrait;
16 use Drupal\Console\Utils\DrupalApi;
17 use Drupal\Console\Utils\Site;
18 use Drupal\Console\Core\Style\DrupalStyle;
21 * Class RebuildCommand
23 * @package Drupal\Console\Command\Cache
25 class RebuildCommand extends Command
39 protected $classLoader;
43 protected $requestStack;
46 * RebuildCommand constructor.
48 * @param DrupalApi $drupalApi
51 * @param RequestStack $requestStack
53 public function __construct(
57 RequestStack $requestStack
59 $this->drupalApi = $drupalApi;
61 $this->classLoader = $classLoader;
62 $this->requestStack = $requestStack;
63 parent::__construct();
69 protected function configure()
72 ->setName('cache:rebuild')
73 ->setDescription($this->trans('commands.cache.rebuild.description'))
76 InputArgument::OPTIONAL,
77 $this->trans('commands.cache.rebuild.options.cache')
84 protected function execute(InputInterface $input, OutputInterface $output)
86 $io = new DrupalStyle($input, $output);
87 $cache = $input->getArgument('cache')?:'all';
88 $this->site->loadLegacyFile('/core/includes/utility.inc');
90 if ($cache && !$this->drupalApi->isValidCache($cache)) {
93 $this->trans('commands.cache.rebuild.messages.invalid_cache'),
102 $io->comment($this->trans('commands.cache.rebuild.messages.rebuild'));
104 if ($cache === 'all') {
105 $this->drupalApi->drupal_rebuild(
107 $this->requestStack->getCurrentRequest()
110 $caches = $this->drupalApi->getCaches();
111 $caches[$cache]->deleteAll();
114 $io->success($this->trans('commands.cache.rebuild.messages.completed'));
122 protected function interact(InputInterface $input, OutputInterface $output)
124 $io = new DrupalStyle($input, $output);
126 $cache = $input->getArgument('cache');
128 $cacheKeys = array_keys($this->drupalApi->getCaches());
130 $cache = $io->choiceNoList(
131 $this->trans('commands.cache.rebuild.questions.cache'),
136 $input->setArgument('cache', $cache);