5 * Miscellaneous functions.
8 use Drupal\Core\PhpStorage\PhpStorageFactory;
9 use Drupal\Core\Cache\Cache;
10 use Drupal\Core\DrupalKernel;
11 use Symfony\Component\HttpFoundation\Request;
14 * Rebuilds all caches even when Drupal itself does not work.
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.
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();
32 // Force kernel to rebuild php cache.
33 PhpStorageFactory::get('twig')->deleteAll();
35 // Bootstrap up to where caches exist and clear them.
36 $kernel = new DrupalKernel('prod', $class_loader);
37 $kernel->setSitePath(DrupalKernel::findSitePath($request));
39 // Invalidate the container.
40 $kernel->invalidateContainer();
42 // Prepare a NULL request.
43 $kernel->prepareLegacyRequest($request);
45 foreach (Cache::getBins() as $bin) {
49 // Disable recording of cached pages.
50 \Drupal::service('page_cache_kill_switch')->trigger();
52 drupal_flush_all_caches();
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');