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'),
76 )->setAliases(['cr']);
82 protected function execute(InputInterface $input, OutputInterface $output)
84 $cache = $input->getArgument('cache')?:'all';
85 $this->site->loadLegacyFile('/core/includes/utility.inc');
87 if ($cache && !$this->drupalApi->isValidCache($cache)) {
88 $this->getIo()->error(
90 $this->trans('commands.cache.rebuild.messages.invalid-cache'),
98 $this->getIo()->newLine();
99 $this->getIo()->comment($this->trans('commands.cache.rebuild.messages.rebuild'));
101 if ($cache === 'all') {
102 $this->drupalApi->drupal_rebuild(
104 $this->requestStack->getCurrentRequest()
107 $caches = $this->drupalApi->getCaches();
108 $caches[$cache]->deleteAll();
111 $this->getIo()->success($this->trans('commands.cache.rebuild.messages.completed'));