rebuild.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * @file
  4. * Rebuilds all Drupal caches even when Drupal itself does not work.
  5. *
  6. * Needs a token query argument which can be calculated using the
  7. * scripts/rebuild_token_calculator.sh script.
  8. *
  9. * @see drupal_rebuild()
  10. */
  11. use Drupal\Component\Utility\Crypt;
  12. use Drupal\Core\DrupalKernel;
  13. use Drupal\Core\Site\Settings;
  14. use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  17. // Change the directory to the Drupal root.
  18. chdir('..');
  19. $autoloader = require_once __DIR__ . '/../autoload.php';
  20. require_once __DIR__ . '/includes/utility.inc';
  21. $request = Request::createFromGlobals();
  22. // Manually resemble early bootstrap of DrupalKernel::boot().
  23. require_once __DIR__ . '/includes/bootstrap.inc';
  24. DrupalKernel::bootEnvironment();
  25. try {
  26. Settings::initialize(dirname(__DIR__), DrupalKernel::findSitePath($request), $autoloader);
  27. }
  28. catch (HttpExceptionInterface $e) {
  29. $response = new Response('', $e->getStatusCode());
  30. $response->prepare($request)->send();
  31. exit;
  32. }
  33. if (Settings::get('rebuild_access', FALSE) ||
  34. ($request->query->get('token') && $request->query->get('timestamp') &&
  35. ((REQUEST_TIME - $request->query->get('timestamp')) < 300) &&
  36. Crypt::hashEquals(Crypt::hmacBase64($request->query->get('timestamp'), Settings::get('hash_salt')), $request->query->get('token'))
  37. )) {
  38. // Clear user cache for all major platforms.
  39. $user_caches = [
  40. 'apcu_clear_cache',
  41. 'wincache_ucache_clear',
  42. 'xcache_clear_cache',
  43. ];
  44. array_map('call_user_func', array_filter($user_caches, 'is_callable'));
  45. drupal_rebuild($autoloader, $request);
  46. drupal_set_message('Cache rebuild complete.');
  47. }
  48. $base_path = dirname(dirname($request->getBaseUrl()));
  49. header('Location: ' . $base_path);