Skip to content

Commit

Permalink
Fixes #3277: Site-specific drush.yml file not loaded.
Browse files Browse the repository at this point in the history
  • Loading branch information
grasmash committed Dec 29, 2017
1 parent 51bf721 commit b8e94bf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
51 changes: 42 additions & 9 deletions src/Config/ConfigLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class ConfigLocator

protected $sources = false;

protected $siteRoots = [];
protected $drupalRoots = [];

protected $siteUris = [];

protected $composerRoot;

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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";
Expand Down
7 changes: 5 additions & 2 deletions src/Preflight/Preflight.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit b8e94bf

Please sign in to comment.