2010-06-28 02:05:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Miscellaneous functions.
|
|
|
|
*/
|
|
|
|
|
2014-04-07 08:14:46 +00:00
|
|
|
use Drupal\Core\PhpStorage\PhpStorageFactory;
|
2013-12-10 13:50:21 +00:00
|
|
|
use Drupal\Core\Cache\Cache;
|
2014-06-26 10:47:01 +00:00
|
|
|
use Drupal\Core\DrupalKernel;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
2013-08-21 07:45:23 +00:00
|
|
|
|
2013-12-10 13:50:21 +00:00
|
|
|
/**
|
|
|
|
* Rebuilds all caches even when Drupal itself does not work.
|
|
|
|
*
|
2016-10-30 19:27:27 +00:00
|
|
|
* @param $class_loader
|
|
|
|
* The class loader. Normally Composer's ClassLoader, as included by the
|
|
|
|
* front controller, but may also be decorated; e.g.,
|
|
|
|
* \Symfony\Component\ClassLoader\ApcClassLoader, \Symfony\Component\ClassLoader\WinCacheClassLoader, or \Symfony\Component\ClassLoader\XcacheClassLoader
|
2014-06-26 10:47:01 +00:00
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request
|
|
|
|
* The current request.
|
|
|
|
*
|
2013-12-10 13:50:21 +00:00
|
|
|
* @see rebuild.php
|
|
|
|
*/
|
2016-10-30 19:27:27 +00:00
|
|
|
function drupal_rebuild($class_loader, Request $request) {
|
2013-12-30 17:58:07 +00:00
|
|
|
// Remove Drupal's error and exception handlers; they rely on a working
|
|
|
|
// service container and other subsystems and will only cause a fatal error
|
|
|
|
// that hides the actual error.
|
|
|
|
restore_error_handler();
|
|
|
|
restore_exception_handler();
|
|
|
|
|
2015-07-07 16:35:44 +00:00
|
|
|
// Force kernel to rebuild php cache.
|
2013-12-10 13:50:21 +00:00
|
|
|
PhpStorageFactory::get('twig')->deleteAll();
|
|
|
|
|
2014-06-05 17:53:24 +00:00
|
|
|
// Bootstrap up to where caches exist and clear them.
|
2015-04-16 13:46:51 +00:00
|
|
|
$kernel = new DrupalKernel('prod', $class_loader);
|
2014-06-26 15:23:53 +00:00
|
|
|
$kernel->setSitePath(DrupalKernel::findSitePath($request));
|
2015-07-07 16:35:44 +00:00
|
|
|
|
|
|
|
// Invalidate the container.
|
|
|
|
$kernel->invalidateContainer();
|
|
|
|
|
|
|
|
// Prepare a NULL request.
|
2014-06-26 10:47:01 +00:00
|
|
|
$kernel->prepareLegacyRequest($request);
|
|
|
|
|
2013-12-10 13:50:21 +00:00
|
|
|
foreach (Cache::getBins() as $bin) {
|
|
|
|
$bin->deleteAll();
|
|
|
|
}
|
|
|
|
|
2014-09-20 10:14:29 +00:00
|
|
|
// Disable recording of cached pages.
|
|
|
|
\Drupal::service('page_cache_kill_switch')->trigger();
|
2014-06-26 10:47:01 +00:00
|
|
|
|
2013-12-10 13:50:21 +00:00
|
|
|
drupal_flush_all_caches();
|
2013-12-30 17:58:07 +00:00
|
|
|
|
|
|
|
// Restore Drupal's error and exception handlers.
|
2014-06-26 10:47:01 +00:00
|
|
|
// @see \Drupal\Core\DrupalKernel::boot()
|
2013-12-30 17:58:07 +00:00
|
|
|
set_error_handler('_drupal_error_handler');
|
|
|
|
set_exception_handler('_drupal_exception_handler');
|
2013-12-10 13:50:21 +00:00
|
|
|
}
|