rebuild.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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->get('token') && $request->get('timestamp') &&
  35. ((REQUEST_TIME - $request->get('timestamp')) < 300) &&
  36. Crypt::hashEquals(Crypt::hmacBase64($request->get('timestamp'), Settings::get('hash_salt')), $request->get('token'))
  37. )) {
  38. // Clear the APCu cache to ensure APCu class loader is reset.
  39. if (function_exists('apcu_clear_cache')) {
  40. apcu_clear_cache();
  41. }
  42. drupal_rebuild($autoloader, $request);
  43. drupal_set_message('Cache rebuild complete.');
  44. }
  45. $base_path = dirname(dirname($request->getBaseUrl()));
  46. header('Location: ' . $base_path);