protected function execute(InputInterface $input, OutputInterface $output) { $drupalAutoLoad = $this->getHelperSet()->get('drupal-autoload'); $drupal_root = $drupalAutoLoad->getDrupalRoot(); require_once $drupal_root . '/core/includes/utility.inc'; $validators = $this->getHelperSet()->get('validators'); // Get the --cache option and make validation $cache = $input->getArgument('cache'); $validated_cache = $validators->validateCache($cache); if (!$validated_cache) { throw new \InvalidArgumentException(sprintf($this->trans('commands.cache.rebuild.messages.invalid_cache'), $cache)); } // Start rebuilding cache $output->writeln(''); $output->writeln('[+] <comment>' . $this->trans('commands.cache.rebuild.messages.rebuild') . '</comment>'); // Get data needed to rebuild cache $kernelHelper = $this->getHelper('kernel'); $classLoader = $kernelHelper->getClassLoader(); $request = $kernelHelper->getRequest(); // Check cache to rebuild if ($cache === 'all') { // If cache is all, then clear all caches \drupal_rebuild($classLoader, $request); } else { // Else, clear the selected cache $caches = $validators->getCaches(); $caches[$cache]->deleteAll(); } // Finish rebuiilding cache $output->writeln('[+] <info>' . $this->trans('commands.cache.rebuild.messages.completed') . '</info>'); }
protected function execute(InputInterface $input, OutputInterface $output) { $output = new DrupalStyle($input, $output); $this->getDrupalHelper()->loadLegacyFile('/core/includes/utility.inc'); $validators = $this->getValidator(); // Get the --cache option and make validation $cache = $input->getArgument('cache'); $validated_cache = $validators->validateCache($cache); if (!$validated_cache) { $output->error(sprintf($this->trans('commands.cache.rebuild.messages.invalid_cache'), $cache)); return; } // Start rebuilding cache $output->newLine(); $output->writeln(sprintf('<comment>%s</comment>', $this->trans('commands.cache.rebuild.messages.rebuild'))); // Get data needed to rebuild cache $kernelHelper = $this->getKernelHelper(); $classLoader = $kernelHelper->getClassLoader(); $request = $kernelHelper->getRequest(); // Check cache to rebuild if ($cache === 'all') { // If cache is all, then clear all caches drupal_rebuild($classLoader, $request); } else { // Else, clear the selected cache $caches = $validators->getCaches(); $caches[$cache]->deleteAll(); } $output->success($this->trans('commands.cache.rebuild.messages.completed')); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $cache = $input->getArgument('cache'); $this->site->loadLegacyFile('/core/includes/utility.inc'); if ($cache && !$this->drupalApi->isValidCache($cache)) { $io->error(sprintf($this->trans('commands.cache.rebuild.messages.invalid_cache'), $cache)); return 1; } $io->newLine(); $io->comment($this->trans('commands.cache.rebuild.messages.rebuild')); if ($cache === 'all') { drupal_rebuild($this->classLoader, $this->requestStack->getCurrentRequest()); } else { $caches = $this->drupalApi->getCaches(); $caches[$cache]->deleteAll(); } $io->success($this->trans('commands.cache.rebuild.messages.completed')); return 0; }
<?php /** * @file * Rebuilds all Drupal caches even when Drupal itself does not work. * * Needs a token query argument which can be calculated using the * scripts/rebuild_token_calculator.sh script. * * @see drupal_rebuild() */ use Drupal\Component\Utility\Crypt; use Drupal\Core\DrupalKernel; use Drupal\Core\Site\Settings; use Symfony\Component\HttpFoundation\Request; // Change the directory to the Drupal root. chdir('..'); $autoloader = (require_once __DIR__ . '/vendor/autoload.php'); require_once __DIR__ . '/includes/utility.inc'; $request = Request::createFromGlobals(); // Manually resemble early bootstrap of DrupalKernel::boot(). require_once __DIR__ . '/includes/bootstrap.inc'; DrupalKernel::bootEnvironment(); Settings::initialize(DrupalKernel::findSitePath($request)); if (Settings::get('rebuild_access', FALSE) || $request->get('token') && $request->get('timestamp') && REQUEST_TIME - $request->get('timestamp') < 300 && $request->get('token') === Crypt::hmacBase64($request->get('timestamp'), Settings::get('hash_salt'))) { drupal_rebuild($autoloader, $request); drupal_set_message('Cache rebuild complete.'); } $base_path = dirname(dirname($request->getBaseUrl())); header('Location: ' . $base_path);
/** * Rebuilds Drupal cache. */ protected function RebuildCache() { require_once DRUPAL_ROOT . '/core/includes/utility.inc'; $kernelHelper = $this->getHelper('kernel'); $classLoader = $kernelHelper->getClassLoader(); $request = $kernelHelper->getRequest(); drupal_rebuild($classLoader, $request); }