From b8e94bfa90f9d6a071c3e27267e984cdd4550917 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Fri, 29 Dec 2017 10:53:51 -0500 Subject: [PATCH] Fixes #3277: Site-specific drush.yml file not loaded. --- src/Config/ConfigLocator.php | 51 +++++++++++++++++++++++++++++------- src/Preflight/Preflight.php | 7 +++-- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/src/Config/ConfigLocator.php b/src/Config/ConfigLocator.php index e43863f7e8..280d7359bb 100644 --- a/src/Config/ConfigLocator.php +++ b/src/Config/ConfigLocator.php @@ -37,7 +37,9 @@ class ConfigLocator protected $sources = false; - protected $siteRoots = []; + protected $drupalRoots = []; + + protected $siteUris = []; protected $composerRoot; @@ -256,26 +258,57 @@ public function addDrushConfig($drushProjectDir) * Add any configuration files found around the Drupal root of the * selected site. * - * @param Path to the selected Drupal site + * @param $drupalRoot + * Path to the selected Drupal site. * @return $this */ - public function addSitewideConfig($siteRoot) + public function addDrupalConfig($drupalRoot) { // There might not be a site. - if (!is_dir($siteRoot)) { + if (!is_dir($drupalRoot)) { return; } // We might have already processed this root. - $siteRoot = realpath($siteRoot); - if (in_array($siteRoot, $this->siteRoots)) { + $drupalRoot = realpath($drupalRoot); + if (in_array($drupalRoot, $this->drupalRoots)) { return; } // Remember that we've seen this location. - $this->siteRoots[] = $siteRoot; + $this->drupalRoots[] = $drupalRoot; + + $this->addConfigPaths(self::DRUPAL_CONTEXT, [ dirname($drupalRoot) . '/drush', "$drupalRoot/drush", "$drupalRoot/sites/all/drush" ]); + return $this; + } + + /** + * Add any configuration files found around the Drupal root of the + * selected site. + * + * @param $drupalRoot + * Path to the selected Drupal site. + * @param $uri + * Site URI. + * + * @return $this + */ + public function addSiteConfig($drupalRoot, $uri) + { + // There might not be a site. + if (!is_dir($drupalRoot)) { + return; + } + + // We might have already processed this site. + if (in_array($uri, $this->siteUris)) { + return; + } + + // Remember that we've seen this site. + $this->siteUris[] = $uri; - $this->addConfigPaths(self::DRUPAL_CONTEXT, [ dirname($siteRoot) . '/drush', "$siteRoot/drush", "$siteRoot/sites/all/drush" ]); + $this->addConfigPaths(self::SITE_CONTEXT, [ "$drupalRoot/sites/$uri", "$drupalRoot/sites/$uri/drush" ]); return $this; } @@ -381,7 +414,7 @@ public function getSiteAliasPaths($paths, Environment $environment) { // In addition to the paths passed in to us (from --alias-paths // commandline options), add some site-local locations. - $base_dirs = array_filter(array_merge($this->siteRoots, [$this->composerRoot])); + $base_dirs = array_filter(array_merge($this->drupalRoots, [$this->composerRoot])); $site_local_paths = array_map( function ($item) { return "$item/drush/sites"; diff --git a/src/Preflight/Preflight.php b/src/Preflight/Preflight.php index d55ef51537..683f6bdba1 100644 --- a/src/Preflight/Preflight.php +++ b/src/Preflight/Preflight.php @@ -249,7 +249,7 @@ public function preflight($argv) // Extend configuration and alias files to include files in // target site. $root = $this->findSelectedSite(); - $this->configLocator->addSitewideConfig($root); + $this->configLocator->addDrupalConfig($root); $this->configLocator->setComposerRoot($this->drupalFinder()->getComposerRoot()); // Look up the locations where alias files may be found. @@ -276,7 +276,10 @@ public function preflight($argv) // If we did not redispatch, then add the site-wide config for the // new root (if the root did in fact change) and continue. - $this->configLocator->addSitewideConfig($root); + $this->configLocator->addDrupalConfig($root); + // Set multisite config using uri from alias. + $uri = $this->aliasManager->getSelf()->uri() ?: 'default'; + $this->configLocator->addSiteConfig($root, $uri); // Remember the paths to all the files we loaded, so that we can // report on it from Drush status or wherever else it may be needed.