diff --git a/commands/core/cache.drush.inc b/commands/core/cache.drush.inc index f911f915e1..c7ed4c92c8 100644 --- a/commands/core/cache.drush.inc +++ b/commands/core/cache.drush.inc @@ -1,6 +1,7 @@ array(), 'arguments' => array(), - 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION, + 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_ROOT, 'core' => array('8+'), 'aliases' => array('cr', 'rebuild'), ); @@ -245,20 +246,25 @@ function drush_cache_clear_drush() { /** * Rebuild a Drupal 8 site. + * + * This is a transpose of core/rebuild.php. Additionally + * it also clears drush cache and drupal render cache. */ function drush_cache_rebuild() { - $drupal_core = drush_get_context('DRUSH_DRUPAL_CORE'); - chdir(dirname($drupal_core)); - $autoloader = require $drupal_core . '/vendor/autoload.php'; - require_once $drupal_core . '/includes/utility.inc'; + chdir(DRUPAL_ROOT); + $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 $drupal_core . '/includes/bootstrap.inc'; + // Manually resemble early bootstrap of DrupalKernel::boot(). + require_once DRUSH_DRUPAL_CORE . '/includes/bootstrap.inc'; DrupalKernel::bootEnvironment(); + Settings::initialize(DrupalKernel::findSitePath($request), $autoloader); // 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.'), '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(); @@ -267,3 +273,4 @@ function drush_cache_rebuild() { drush_include_engine('drupal', 'cache', drush_drupal_major_version()); drush_cache_clear_render(); } + diff --git a/includes/drupal.inc b/includes/drupal.inc index c4db5192c6..4d8f3fbcad 100644 --- a/includes/drupal.inc +++ b/includes/drupal.inc @@ -5,6 +5,17 @@ * Utility functions related to Drupal. */ +/** + * Loads the Drupal autoloader and returns the instance. + */ +function drush_drupal_load_autoloader($drupal_root) { + static $autoloader = FALSE; + if (!$autoloader) { + $autoloader = require_once $drupal_root .'/core/vendor/autoload.php'; + } + return $autoloader; +} + /** * Detects the version number of the current Drupal installation, * if any. Returns FALSE if there is no current Drupal installation, @@ -19,30 +30,31 @@ function drush_drupal_version($drupal_root = NULL) { if (!$version) { if (($drupal_root != NULL) || ($drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT'))) { - // D7 stores VERSION in bootstrap.inc. - $version_constant_paths = array('/includes/bootstrap.inc', '/modules/system/system.module'); - foreach ($version_constant_paths as $path) { - if (file_exists($drupal_root . $path)) { - require_once $drupal_root . $path; - if (defined('VERSION')) { - $version = VERSION; - break; - } - } - } - // We just might be dealing with an early Drupal version (pre 4.7) - if (defined('VERSION')) { - $version = VERSION; - } - elseif (file_exists($drupal_root . '/core/vendor/autoload.php')) { + // Try and find D8. + if (file_exists($drupal_root . '/core/vendor/autoload.php')) { + drush_include_engine('drupal', 'environment'); // Load the autoloader so we can access the class constants. - require_once $drupal_root .'/core/vendor/autoload.php'; - // Drush depends on bootstrap being loaded at this point; + drush_drupal_load_autoloader($drupal_root); + // Drush depends on bootstrap being loaded at this point. require_once $drupal_root .'/core/includes/bootstrap.inc'; if (defined('Drupal::VERSION')) { $version = Drupal::VERSION; } } + else { + // D7 stores VERSION in bootstrap.inc. + // D6 and below does it in system.module. + $version_constant_paths = array('/includes/bootstrap.inc', '/modules/system/system.module'); + foreach ($version_constant_paths as $path) { + if (file_exists($drupal_root . $path)) { + require_once $drupal_root . $path; + if (defined('VERSION')) { + $version = VERSION; + break; + } + } + } + } } } return $version;