11<?php
22namespace Drush \Commands \core ;
33
4+ use Composer \Semver \Comparator ;
45use Consolidation \AnnotatedCommand \CommandData ;
56use Drupal \Core \Database \ConnectionNotDefinedException ;
67use Drush \Commands \DrushCommands ;
@@ -19,25 +20,6 @@ class SiteInstallCommands extends DrushCommands implements SiteAliasManagerAware
1920{
2021 use SiteAliasManagerAwareTrait;
2122
22- /**
23- * Drupal version exploded.
24- *
25- * eg. [8,6,0-alpha1]
26- *
27- * @var array
28- */
29- protected $ version_parts = [];
30-
31- /**
32- * {@inheritdoc}
33- */
34- public function __construct ()
35- {
36- $ drupal_root = Drush::bootstrapManager ()->getRoot ();
37- $ version = Drush::bootstrap ()->getVersion ($ drupal_root );
38- $ this ->version_parts = explode ('. ' , $ version );
39- }
40-
4123 /**
4224 * Install Drupal along with modules/themes/configuration/profile.
4325 *
@@ -159,8 +141,8 @@ public function install(array $profile, $options = ['db-url' => self::REQ, 'db-p
159141 protected function determineProfile ($ profile , $ options , $ class_loader )
160142 {
161143 // --config-dir fails with Standard profile and any other one that carries content entities.
162- // Force to minimal install profile only for drupal <= 8.5.x .
163- if ($ options ['config-dir ' ] && $ this -> version_parts [ 0 ] <= 8 && $ this -> version_parts [ 1 ] <= 5 ) {
144+ // Force to minimal install profile only for drupal < 8.6 .
145+ if ($ options ['config-dir ' ] && Comparator:: lessThan ( self :: getVersion (), ' 8.6 ' ) ) {
164146 $ this ->logger ()->info (dt ("Using 'minimal' install profile since --config-dir option was provided. " ));
165147 $ profile = 'minimal ' ;
166148 }
@@ -202,8 +184,7 @@ protected function determineProfile($profile, $options, $class_loader)
202184 */
203185 public function post ($ result , CommandData $ commandData )
204186 {
205- // Only for drupal <= 8.5.x.
206- if ($ config = $ commandData ->input ()->getOption ('config-dir ' ) && $ this ->version_parts [0 ] <= 8 && $ this ->version_parts [1 ] <= 5 ) {
187+ if ($ config = $ commandData ->input ()->getOption ('config-dir ' ) && Comparator::lessThan (self ::getVersion (), '8.6 ' )) {
207188 // Set the destination site UUID to match the source UUID, to bypass a core fail-safe.
208189 $ source_storage = new FileStorage ($ config );
209190 $ options = ['yes ' => true ];
@@ -383,6 +364,7 @@ protected function getSitesSubdirFromUri($root, $uri)
383364 $ sites_file = $ root . '/sites/sites.php ' ;
384365 if (file_exists ($ sites_file )) {
385366 include $ sites_file ;
367+ /** @var array $sites */
386368 if (array_key_exists ($ uri , $ sites )) {
387369 return $ sites [$ uri ];
388370 }
@@ -394,6 +376,11 @@ protected function getSitesSubdirFromUri($root, $uri)
394376 return false ;
395377 }
396378
379+ public static function getVersion () {
380+ $ drupal_root = Drush::bootstrapManager ()->getRoot ();
381+ return Drush::bootstrap ()->getVersion ($ drupal_root );
382+ }
383+
397384 /**
398385 * Fake the necessary HTTP headers that the Drupal installer still needs:
399386 * @see https://github.com/drupal/drupal/blob/d260101f1ea8a6970df88d2f1899248985c499fc/core/includes/install.core.inc#L287
0 commit comments