5 * Rebuilds all Drupal caches even when Drupal itself does not work.
7 * Needs a token query argument which can be calculated using the
8 * scripts/rebuild_token_calculator.sh script.
10 * @see drupal_rebuild()
13 use Drupal\Component\Utility\Crypt;
14 use Drupal\Core\DrupalKernel;
15 use Drupal\Core\Site\Settings;
16 use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
17 use Symfony\Component\HttpFoundation\Request;
18 use Symfony\Component\HttpFoundation\Response;
20 // Change the directory to the Drupal root.
23 $autoloader = require_once __DIR__ . '/../autoload.php';
24 require_once __DIR__ . '/includes/utility.inc';
26 $request = Request::createFromGlobals();
27 // Manually resemble early bootstrap of DrupalKernel::boot().
28 require_once __DIR__ . '/includes/bootstrap.inc';
29 DrupalKernel::bootEnvironment();
32 Settings::initialize(dirname(__DIR__), DrupalKernel::findSitePath($request), $autoloader);
34 catch (HttpExceptionInterface $e) {
35 $response = new Response('', $e->getStatusCode());
36 $response->prepare($request)->send();
40 if (Settings::get('rebuild_access', FALSE) ||
41 ($request->query->get('token') && $request->query->get('timestamp') &&
42 ((REQUEST_TIME - $request->query->get('timestamp')) < 300) &&
43 Crypt::hashEquals(Crypt::hmacBase64($request->query->get('timestamp'), Settings::get('hash_salt')), $request->query->get('token'))
45 // Clear user cache for all major platforms.
48 'wincache_ucache_clear',
51 array_map('call_user_func', array_filter($user_caches, 'is_callable'));
53 drupal_rebuild($autoloader, $request);
54 drupal_set_message('Cache rebuild complete.');
56 $base_path = dirname(dirname($request->getBaseUrl()));
57 header('Location: ' . $base_path);