From 3102b026bbd8da296db07a5c5c9e1711754f6d8f Mon Sep 17 00:00:00 2001 From: Nate Haug Date: Thu, 29 Oct 2015 21:00:06 -0700 Subject: [PATCH] Issue #1724: Move logic for version information into Boot classes. --- includes/drupal.inc | 26 +++----------------------- lib/Drush/Boot/BaseBoot.php | 3 +++ lib/Drush/Boot/Boot.php | 11 +++++++++++ lib/Drush/Boot/DrupalBoot.php | 3 +++ lib/Drush/Boot/DrupalBoot6.php | 10 ++++++++++ lib/Drush/Boot/DrupalBoot7.php | 10 ++++++++++ lib/Drush/Boot/DrupalBoot8.php | 10 ++++++++++ 7 files changed, 50 insertions(+), 23 deletions(-) diff --git a/includes/drupal.inc b/includes/drupal.inc index b24dc52397..0c93674063 100644 --- a/includes/drupal.inc +++ b/includes/drupal.inc @@ -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); } } } diff --git a/lib/Drush/Boot/BaseBoot.php b/lib/Drush/Boot/BaseBoot.php index 10740ecdca..f1b9fcca80 100644 --- a/lib/Drush/Boot/BaseBoot.php +++ b/lib/Drush/Boot/BaseBoot.php @@ -10,6 +10,9 @@ function __construct() { function valid_root($path) { } + function get_version($root) { + } + function command_defaults() { } diff --git a/lib/Drush/Boot/Boot.php b/lib/Drush/Boot/Boot.php index 4c8b71d2a1..5e7074497b 100644 --- a/lib/Drush/Boot/Boot.php +++ b/lib/Drush/Boot/Boot.php @@ -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. diff --git a/lib/Drush/Boot/DrupalBoot.php b/lib/Drush/Boot/DrupalBoot.php index 61f6357240..72d5a3c0d0 100644 --- a/lib/Drush/Boot/DrupalBoot.php +++ b/lib/Drush/Boot/DrupalBoot.php @@ -10,6 +10,9 @@ function __construct() { function valid_root($path) { } + function get_version($drupal_root) { + } + function get_profile() { } diff --git a/lib/Drush/Boot/DrupalBoot6.php b/lib/Drush/Boot/DrupalBoot6.php index ab06729b03..ccb8b7bc1c 100644 --- a/lib/Drush/Boot/DrupalBoot6.php +++ b/lib/Drush/Boot/DrupalBoot6.php @@ -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'); } diff --git a/lib/Drush/Boot/DrupalBoot7.php b/lib/Drush/Boot/DrupalBoot7.php index c5726d2ace..651b8f0097 100644 --- a/lib/Drush/Boot/DrupalBoot7.php +++ b/lib/Drush/Boot/DrupalBoot7.php @@ -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(); } diff --git a/lib/Drush/Boot/DrupalBoot8.php b/lib/Drush/Boot/DrupalBoot8.php index 505e175b94..5235939d80 100644 --- a/lib/Drush/Boot/DrupalBoot8.php +++ b/lib/Drush/Boot/DrupalBoot8.php @@ -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(); }