2010-06-28 02:05:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Miscellaneous functions.
|
|
|
|
*/
|
|
|
|
|
2013-08-21 07:45:23 +00:00
|
|
|
use Drupal\Component\Utility\Variable;
|
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;
|
|
|
|
use Composer\Autoload\ClassLoader;
|
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.
|
|
|
|
*
|
2014-06-26 10:47:01 +00:00
|
|
|
* @param \Composer\Autoload\ClassLoader $classloader
|
|
|
|
* The classloader.
|
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request
|
|
|
|
* The current request.
|
|
|
|
*
|
2013-12-10 13:50:21 +00:00
|
|
|
* @see rebuild.php
|
|
|
|
*/
|
2014-06-26 10:47:01 +00:00
|
|
|
function drupal_rebuild(ClassLoader $classloader, 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();
|
|
|
|
|
2014-06-26 10:47:01 +00:00
|
|
|
// Force kernel to rebuild container.
|
2013-12-10 13:50:21 +00:00
|
|
|
PhpStorageFactory::get('service_container')->deleteAll();
|
|
|
|
PhpStorageFactory::get('twig')->deleteAll();
|
|
|
|
|
2014-06-05 17:53:24 +00:00
|
|
|
// Bootstrap up to where caches exist and clear them.
|
2014-06-26 10:47:01 +00:00
|
|
|
$kernel = new DrupalKernel('prod', $classloader);
|
2014-06-26 15:23:53 +00:00
|
|
|
$kernel->setSitePath(DrupalKernel::findSitePath($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
|
|
|
}
|