Skip to content

Commit

Permalink
Issue drush-ops#1724: Move logic for version information into Boot cl…
Browse files Browse the repository at this point in the history
…asses.
  • Loading branch information
quicksketch authored and mikeker committed Feb 21, 2017
1 parent 0878e99 commit f213d08
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 23 deletions.
26 changes: 3 additions & 23 deletions includes/drupal.inc
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,9 @@ function drush_drupal_version($drupal_root = NULL) {

if (!$version) {
if (($drupal_root != NULL) || ($drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT'))) {
// Try and find D8.
if (file_exists($drupal_root . '/autoload.php')) {
// Load the autoloader so we can access the class constants.
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;
}
}
}
$bootstrap = drush_bootstrap_class_for_root($drupal_root);
if ($bootstrap) {
$version = $bootstrap->get_version($drupal_root);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Drush/Boot/BaseBoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ function __construct() {
function valid_root($path) {
}

function get_version($root) {
}

function command_defaults() {
}

Expand Down
11 changes: 11 additions & 0 deletions lib/Drush/Boot/Boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ interface Boot {
*/
function valid_root($path);


/**
* Given a site root directory, determine the exact version of the software.
*
* @param string $root
* The full path to the site installation, with no trailing slash.
* @return string|NULL
* The version string for the current version of the software, e.g. 8.1.3
*/
function get_version($root);

/**
* Main entrypoint to bootstrap the selected CMS and
* execute the selected command.
Expand Down
3 changes: 3 additions & 0 deletions lib/Drush/Boot/DrupalBoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ function __construct() {
function valid_root($path) {
}

function get_version($drupal_root) {
}

function get_profile() {
}

Expand Down
11 changes: 11 additions & 0 deletions lib/Drush/Boot/DrupalBoot6.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ function valid_root($path) {
}
}

function get_version($drupal_root) {
$path = $drupal_root . '/modules/system/system.module';
if (is_file($path)) {
require_once $path;
if (defined('VERSION')) {
return VERSION;
}
}
}

function get_profile() {
return variable_get('install_profile', 'standard');
}
Expand Down Expand Up @@ -47,6 +57,7 @@ function contrib_themes_paths() {

function bootstrap_drupal_core($drupal_root) {
define('DRUPAL_ROOT', $drupal_root);
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
$core = DRUPAL_ROOT;

return $core;
Expand Down
11 changes: 11 additions & 0 deletions lib/Drush/Boot/DrupalBoot7.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ function valid_root($path) {
}
}

function get_version($drupal_root) {
$path = $drupal_root . '/includes/bootstrap.inc';
if (is_file($path)) {
require_once $path;
if (defined('VERSION')) {
return VERSION;
}
}
}

function get_profile() {
return drupal_get_profile();
}
Expand Down Expand Up @@ -44,6 +54,7 @@ function contrib_themes_paths() {

function bootstrap_drupal_core($drupal_root) {
define('DRUPAL_ROOT', $drupal_root);
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
$core = DRUPAL_ROOT;

return $core;
Expand Down
10 changes: 10 additions & 0 deletions lib/Drush/Boot/DrupalBoot8.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ function valid_root($path) {
}
}

function get_version($drupal_root) {
// Load the autoloader so we can access the class constants.
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')) {
return \Drupal::VERSION;
}
}

function get_profile() {
return drupal_get_profile();
}
Expand Down

0 comments on commit f213d08

Please sign in to comment.