Upgraded drupal core with security updates
[yaffs-website] / web / core / includes / utility.inc
1 <?php
2
3 /**
4  * @file
5  * Miscellaneous functions.
6  */
7
8 use Drupal\Core\PhpStorage\PhpStorageFactory;
9 use Drupal\Core\Cache\Cache;
10 use Drupal\Core\DrupalKernel;
11 use Symfony\Component\HttpFoundation\Request;
12
13 /**
14  * Rebuilds all caches even when Drupal itself does not work.
15  *
16  * @param $class_loader
17  *   The class loader. Normally Composer's ClassLoader, as included by the
18  *   front controller, but may also be decorated; e.g.,
19  *   \Symfony\Component\ClassLoader\ApcClassLoader, \Symfony\Component\ClassLoader\WinCacheClassLoader, or \Symfony\Component\ClassLoader\XcacheClassLoader
20  * @param \Symfony\Component\HttpFoundation\Request $request
21  *   The current request.
22  *
23  * @see rebuild.php
24  */
25 function drupal_rebuild($class_loader, Request $request) {
26   // Remove Drupal's error and exception handlers; they rely on a working
27   // service container and other subsystems and will only cause a fatal error
28   // that hides the actual error.
29   restore_error_handler();
30   restore_exception_handler();
31
32   // Force kernel to rebuild php cache.
33   PhpStorageFactory::get('twig')->deleteAll();
34
35   // Bootstrap up to where caches exist and clear them.
36   $kernel = new DrupalKernel('prod', $class_loader);
37   $kernel->setSitePath(DrupalKernel::findSitePath($request));
38
39   // Invalidate the container.
40   $kernel->invalidateContainer();
41
42   // Prepare a NULL request.
43   $kernel->prepareLegacyRequest($request);
44
45   foreach (Cache::getBins() as $bin) {
46     $bin->deleteAll();
47   }
48
49   // Disable recording of cached pages.
50   \Drupal::service('page_cache_kill_switch')->trigger();
51
52   drupal_flush_all_caches();
53
54   // Restore Drupal's error and exception handlers.
55   // @see \Drupal\Core\DrupalKernel::boot()
56   set_error_handler('_drupal_error_handler');
57   set_exception_handler('_drupal_exception_handler');
58 }