Skip to content

Commit

Permalink
Update cache-rebuild to align with latest code in core/rebuild.php. A…
Browse files Browse the repository at this point in the history
…lso reduce bootstrap level to DRUSH_BOOTSTRAP_DRUPAL_ROOT.
  • Loading branch information
jonhattan committed Oct 5, 2014
1 parent 690cbc7 commit d809c2d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 25 deletions.
21 changes: 14 additions & 7 deletions commands/core/cache.drush.inc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Drupal\Core\DrupalKernel;
use Drupal\Core\Site\Settings;
use Symfony\Component\HttpFoundation\Request;

/**
Expand Down Expand Up @@ -75,7 +76,7 @@ function cache_drush_command() {
// do the same
'options' => array(),
'arguments' => array(),
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION,
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_ROOT,
'core' => array('8+'),
'aliases' => array('cr', 'rebuild'),
);
Expand Down Expand Up @@ -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();
Expand All @@ -267,3 +273,4 @@ function drush_cache_rebuild() {
drush_include_engine('drupal', 'cache', drush_drupal_major_version());
drush_cache_clear_render();
}

48 changes: 30 additions & 18 deletions includes/drupal.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down

0 comments on commit d809c2d

Please sign in to comment.