Security update for permissions_by_term
[yaffs-website] / web / core / rebuild.php
1 <?php
2
3 /**
4  * @file
5  * Rebuilds all Drupal caches even when Drupal itself does not work.
6  *
7  * Needs a token query argument which can be calculated using the
8  * scripts/rebuild_token_calculator.sh script.
9  *
10  * @see drupal_rebuild()
11  */
12
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;
19
20 // Change the directory to the Drupal root.
21 chdir('..');
22
23 $autoloader = require_once __DIR__ . '/../autoload.php';
24 require_once __DIR__ . '/includes/utility.inc';
25
26 $request = Request::createFromGlobals();
27 // Manually resemble early bootstrap of DrupalKernel::boot().
28 require_once __DIR__ . '/includes/bootstrap.inc';
29 DrupalKernel::bootEnvironment();
30
31 try {
32   Settings::initialize(dirname(__DIR__), DrupalKernel::findSitePath($request), $autoloader);
33 }
34 catch (HttpExceptionInterface $e) {
35   $response = new Response('', $e->getStatusCode());
36   $response->prepare($request)->send();
37   exit;
38 }
39
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'))
44   )) {
45   // Clear user cache for all major platforms.
46   $user_caches = [
47     'apcu_clear_cache',
48     'wincache_ucache_clear',
49     'xcache_clear_cache',
50   ];
51   array_map('call_user_func', array_filter($user_caches, 'is_callable'));
52
53   drupal_rebuild($autoloader, $request);
54   drupal_set_message('Cache rebuild complete.');
55 }
56 $base_path = dirname(dirname($request->getBaseUrl()));
57 header('Location: ' . $base_path);