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