diff --git a/commands/core/archive.drush.inc b/commands/core/archive.drush.inc index acd7cb1976..c52990a43e 100644 --- a/commands/core/archive.drush.inc +++ b/commands/core/archive.drush.inc @@ -21,7 +21,7 @@ function archive_drush_command() { 'destination' => 'The full path and filename in which the archive should be stored. If omitted, it will be saved to the drush-backups directory and a filename will be generated.', 'overwrite' => 'Do not fail if the destination file exists; overwrite it instead. Default is --no-overwrite.', 'generator' => 'The generator name to store in the MANIFEST file. The default is "Drush archive-dump".', - 'generatorversion' => 'The generator version number to store in the MANIFEST file. The default is ' . DRUSH_VERSION . '.', + 'generatorversion' => 'The generator version number to store in the MANIFEST file. The default is ' . Drush::getMajorVersion() . '.', 'pipe' => 'Only print the destination of the archive. Useful for scripts that don\'t pass --destination.', 'preserve-symlinks' => 'Preserve symbolic links.', 'no-core' => 'Exclude Drupal core, so the backup only contains the site specific stuff.', @@ -232,7 +232,7 @@ function drush_archive_dump($sites_subdirs = '@self') { 'datestamp' => time(), 'formatversion' => '1.0', 'generator' => drush_get_option('generator', 'Drush archive-dump'), - 'generatorversion' => drush_get_option('generatorversion', DRUSH_VERSION), + 'generatorversion' => drush_get_option('generatorversion', Drush::getMajorVersion()), 'description' => drush_get_option('description', ''), 'tags' => drush_get_option('tags', ''), 'archiveformat' => ($include_platform ? 'platform' : 'site'), diff --git a/commands/core/core.drush.inc b/commands/core/core.drush.inc index 13790146c8..a494883dc9 100644 --- a/commands/core/core.drush.inc +++ b/commands/core/core.drush.inc @@ -6,6 +6,7 @@ */ use Drush\Log\LogLevel; +use SebastianBergmann\Version; /** * Implementation of hook_drush_help(). @@ -610,7 +611,7 @@ function _core_site_status_table($project = '') { $status_table['php-conf'] = $php_ini_files; } $status_table['drush-script'] = DRUSH_COMMAND; - $status_table['drush-version'] = DRUSH_VERSION; + $status_table['drush-version'] = Drush::getVersion(); $status_table['drush-temp'] = drush_find_tmp(); $status_table['drush-conf'] = drush_flatten_array(drush_get_context_options('context-path', '')); $alias_files = _drush_sitealias_find_alias_files(); @@ -1280,7 +1281,7 @@ function drush_core_drupal_directory($target = 'root') { * Called for `drush version` or `drush --version` */ function drush_core_version() { - return DRUSH_VERSION; + return Drush::getVersion(); } /** diff --git a/includes/cache.inc b/includes/cache.inc index 8f62193832..c6c1cbdedc 100644 --- a/includes/cache.inc +++ b/includes/cache.inc @@ -197,5 +197,5 @@ function drush_get_cid($prefix, $contexts = array(), $params = array()) { $cid[] = $param; } - return DRUSH_VERSION . '-' . $prefix . '-' . md5(implode("", $cid)); + return Drush::getVersion() . '-' . $prefix . '-' . md5(implode("", $cid)); } diff --git a/includes/preflight.inc b/includes/preflight.inc index f52894f9b4..7840f4d653 100644 --- a/includes/preflight.inc +++ b/includes/preflight.inc @@ -175,13 +175,20 @@ function drush_preflight_prepare() { drush_set_context('DRUSH_VENDOR_PATH', dirname($vendor_path)); drush_set_context('DRUSH_CLASSLOADER', $classloader); - // Set up for backwards-compatibility. New code should call - // \Drush::getVersion() and \Drush::getMajorVersion() directly - $drush_version = \Drush::getVersion(); - $version_parts = explode('.', $drush_version); - define('DRUSH_VERSION', $drush_version); - define('DRUSH_MAJOR_VERSION', $version_parts[0]); - define('DRUSH_MINOR_VERSION', $version_parts[1]); + /* + * @deprecated. Use \Drush::getVersion(). + */ + define('DRUSH_VERSION', \Drush::getVersion()); + + /* + * @deprecated. Use \Drush::getMajorVersion(). + */ + define('DRUSH_MAJOR_VERSION', Drush::getMajorVersion()); + + /* + * @deprecated. Use \Drush::getMinorVersion(). + */ + define('DRUSH_MINOR_VERSION', Drush::getMinorVersion()); // We need to load our services right away, as we cannot log // or do much else until after this is done. diff --git a/lib/Drush.php b/lib/Drush.php index 67a5841414..d95d305dc4 100644 --- a/lib/Drush.php +++ b/lib/Drush.php @@ -6,6 +6,7 @@ */ use League\Container\ContainerInterface; +use SebastianBergmann\Version; /** * Static Service Container wrapper. @@ -60,7 +61,8 @@ class Drush { public static function getVersion() { if (!static::$version) { $drush_info = static::drush_read_drush_info(); - static::$version = $drush_info['drush_version']; + $instance = new Version($drush_info['drush_version'], DRUSH_BASE_PATH); + static::$version = $instance->getversion(); } return static::$version; } diff --git a/lib/Drush/Boot/DrupalBoot.php b/lib/Drush/Boot/DrupalBoot.php index c6aa728bfd..90b36af3f2 100644 --- a/lib/Drush/Boot/DrupalBoot.php +++ b/lib/Drush/Boot/DrupalBoot.php @@ -282,7 +282,7 @@ function bootstrap_drupal_root_validate() { $version = drush_drupal_version($drupal_root); $major_version = drush_drupal_major_version($drupal_root); if ($major_version <= 6) { - return drush_set_error('DRUSH_DRUPAL_VERSION_UNSUPPORTED', dt('Drush !drush_version does not support Drupal !major_version.', array('!drush_version' => DRUSH_VERSION, '!major_version' => $major_version))); + return drush_set_error('DRUSH_DRUPAL_VERSION_UNSUPPORTED', dt('Drush !drush_version does not support Drupal !major_version.', array('!drush_version' => \Drush::getMajorVersion(), '!major_version' => $major_version))); } drush_bootstrap_value('drupal_root', $drupal_root);