function drush_cache_rebuild

8.0.x cache.drush.inc drush_cache_rebuild()
7.x cache.drush.inc drush_cache_rebuild()
master cache.drush.inc drush_cache_rebuild()

Rebuild a Drupal 8 site.

This is a transpose of core/rebuild.php. Additionally it also clears drush cache and drupal render cache.

File

commands/core/cache.drush.inc, line 263

Code

function drush_cache_rebuild() {
  if (!drush_get_option('cache-clear', TRUE)) {
    drush_log(dt("Skipping cache-clear operation due to --cache-clear=0 option."), LogLevel::OK);
    return TRUE;
  }
  chdir(DRUPAL_ROOT);

  // Clear the APC cache to ensure APC class loader is reset.
  if (function_exists('apc_fetch')) {
    apc_clear_cache('user');
  }

  $autoloader = drush_drupal_load_autoloader(DRUPAL_ROOT);
  require_once DRUSH_DRUPAL_CORE . '/includes/utility.inc';

  $request = Request::createFromGlobals();
  // Manually resemble early bootstrap of DrupalKernel::boot().
  require_once DRUSH_DRUPAL_CORE . '/includes/bootstrap.inc';
  DrupalKernel::bootEnvironment();
  // Avoid 'Only variables should be passed by reference'
  $root = DRUPAL_ROOT;
  $site_path = DrupalKernel::findSitePath($request);
  Settings::initialize($root, $site_path, $autoloader);

  // Use our error handler since _drupal_log_error() depends on an unavailable theme system (ugh).
  set_error_handler('drush_error_handler');

  // drupal_rebuild() calls drupal_flush_all_caches() itself, so we don't do it manually.
  drupal_rebuild($autoloader, $request);
  drush_log(dt('Cache rebuild complete.'), LogLevel::OK);

  // As this command replaces `drush cache-clear all` for Drupal 8 users, clear
  // the Drush cache as well, for consistency with that behavior.
  drush_cache_clear_drush();
}