Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global Drush9 should redispatch to site-local drush8 even if alias record not found #3274

Closed
weitzman opened this issue Dec 28, 2017 · 7 comments

Comments

@weitzman
Copy link
Member

weitzman commented Dec 28, 2017

I can easily work around this problem, but I'd like to document it. The request I am making is drush @bh.dev4 uli. The exception I get is [preflight] The alias @bh.dev4 could not be found..

// Determine the local site targeted, if any.
// Extend configuration and alias files to include files in
// target site.
$root = $this->findSelectedSite();
$this->configLocator->addSitewideConfig($root);
$this->configLocator->setComposerRoot($this->drupalFinder()->getComposerRoot());
// Look up the locations where alias files may be found.
$paths = $this->configLocator->getSiteAliasPaths($this->preflightArgs->aliasPaths(), $this->environment);
// Configure alias manager.
$this->aliasManager = (new SiteAliasManager())->addSearchLocations($paths);
$this->aliasManager->setReferenceData($config->export());
$selfAliasRecord = $this->aliasManager->findSelf($this->preflightArgs, $this->environment, $root);
$this->configLocator->addAliasConfig($selfAliasRecord->exportConfig());
// Process the selected alias. This might change the selected site,
// so we will add new site-wide config location for the new root.
$root = $this->setSelectedSite($selfAliasRecord->localRoot());
// Now that we have our final Drupal root, check to see if there is
// a site-local Drush. If there is, we will redispatch to it.
// NOTE: termination handlers have not been set yet, so it is okay
// to exit early without taking special action.
$status = RedispatchToSiteLocal::redispatchIfSiteLocalDrush($argv, $root, $this->environment->vendorPath(), $this->logger()) ;

I have a Composer project with drush8 as the site-local Drush. I'm using Drush9 as a global launcher (not recommended, but "happens to work"). I am getting an error at line 261 above. The issue that Drush9 is looking for a self.site.yml file in COMPOSER_ROOT/drush but this site has bh.aliases.drushrc.php. So no alias is found and we get an exception instead of reaching the redispatch in line 272.

Seems like we need to catch the exception, or move the redispatch earlier.

@weitzman
Copy link
Member Author

Note that the drush-launcher handles this situation just fine, as it hands off to site local drush without trying to handle the site alias.

@greg-1-anderson greg-1-anderson changed the title Global Drush9 not finding drush8 site aliases during preflight Global Drush9 should redispatch to site-local drush8 even if alias record not found Dec 28, 2017
@greg-1-anderson
Copy link
Member

Yes, this is a question of priorities. The use-case you describe should work.

I think that Drush 9 as a launcher should be a supported feature.

@Schnitzel
Copy link
Contributor

We got this issue at lagoon now, basically we want to ship always with the newest Drush globally in the docker image installed, but then a client might have a site that is still running with Drush 8 and also want's to use the SiteAliases of Drush 8.

We currently work around this issue with installing the newest Version of Drush 8, but that's not the best solution for the future.

Would moving the Redispatcher earlier create other issues?

@weitzman
Copy link
Member Author

weitzman commented Feb 5, 2018 via email

@greg-1-anderson
Copy link
Member

Catching the exception is undesirable, as that would entail an awkward duplication of the redispatch code.

Moving the redispatch code earlier works for this failure case, but does not work for other cases (e.g. when using an alias that is found to select a Drupal site that has a site-local Drush).

I think that postponing throwing the exception until later will work, if we make it no longer the responsibility of PreflightSiteLocatior::findSite (in the current code -- aliasManager->findSelf above).

PR coming.

greg-1-anderson added a commit that referenced this issue Aug 14, 2018
@greg-1-anderson
Copy link
Member

I merged the PR that should fix this into dev-master, but I don't have a test site with site-local Drush 8 and some site-local aliases. Please confirm this is working now with latest master.

@weitzman
Copy link
Member Author

weitzman commented Sep 4, 2018

Confirmed fixed.

@weitzman weitzman closed this as completed Sep 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants