2010-06-28 02:05:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Miscellaneous functions.
|
|
|
|
*/
|
|
|
|
|
Revert "Issue #2752961 by dawehner, Wim Leers, Jo Fitzgerald, bradjones1, chr.fritsch, greg.1.anderson, anavarre, Berdir, moshe weitzman, bkosborne, alexpott, Crell, catch, msonnabaum, lauriii, joelpittet, deviantintegral, cilefen, effulgentsia, xjm: No reliable method exists for clearing the Twig cache"
This reverts commit ada497ac26f833eaa9f227edff6a919ec5da6252.
2018-05-05 00:19:42 +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
|
2020-08-27 09:09:38 +00:00
|
|
|
* front controller, but may also be decorated.
|
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.
|
Revert "Issue #2752961 by dawehner, Wim Leers, Jo Fitzgerald, bradjones1, chr.fritsch, greg.1.anderson, anavarre, Berdir, moshe weitzman, bkosborne, alexpott, Crell, catch, msonnabaum, lauriii, joelpittet, deviantintegral, cilefen, effulgentsia, xjm: No reliable method exists for clearing the Twig cache"
This reverts commit ada497ac26f833eaa9f227edff6a919ec5da6252.
2018-05-05 00:19:42 +00:00
|
|
|
PhpStorageFactory::get('twig')->deleteAll();
|
2013-12-10 13:50:21 +00:00
|
|
|
|
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));
|
2019-08-12 21:45:20 +00:00
|
|
|
$kernel->boot();
|
|
|
|
$kernel->preHandle($request);
|
|
|
|
// Ensure our request includes the session if appropriate.
|
|
|
|
if (PHP_SAPI !== 'cli') {
|
|
|
|
$request->setSession($kernel->getContainer()->get('session'));
|
|
|
|
}
|
2015-07-07 16:35:44 +00:00
|
|
|
|
|
|
|
// Invalidate the container.
|
|
|
|
$kernel->invalidateContainer();
|
|
|
|
|
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
|
|
|
}
|