Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.Hello.
I've been having this issue with drush in a multsite configuration using both drush aliases (to specify where I want to install) and drupal site aliases (sites.php).
Let me see if I can make myself clear enough :)
So, I have this situation:
sites/mysitedir
is my site folder.
Than in
sites/sites.php
I have two domains pointing to the same site folder
a.mysite.com
b.mysite.comI also have drush aliases for both domains:
@mysite.a
@mysite.b
Both these two drush aliases are supposed to work off of the sites/mysitedir. And they do with all other commands. But when I happen to need to rebuild the site from a profile and I run
drush @mysite.a si <profile-name>
drush does not "understand" that a.mysite.com points to the sites/mysitedir and it will try to create a sites/a.mysite.com directory. However, I want it to use my sites/mysitedir.
Am I doing anything wrong?
In the meantime, as a quick fix for myself, I patched the my site-install command.
Patch is attached.
Bear in mind I am not an expert of drush internals, nor I am of all the options he has.
Thank you very much.
Regards,
Vincenzo
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | drush-alias-multisite-install-v2-14.patch | 811 bytes | wamilton |
| #14 | drush-si-6-test-subdir-redundant-14.patch | 918 bytes | wamilton |
| #12 | drush-alias-multisite-install-v2-12.patch | 1.61 KB | wamilton |
| #2 | drush-alias-multisite-install-v2.patch | 696 bytes | Vincenzo |
| drush-alias-multisite-install.patch | 850 bytes | Vincenzo |
Comments
Comment #1
greg.1.anderson commentedThis patch is definitely moving in the right direction; setting $sites_subdir is the correct solution. However,
drush_get_context('DRUSH_TARGET_SITE_ALIAS')will return an empty array if the user did not specify an alias on the commandline (e.g. if the site was specified via cwd). Perhapsdrush_get_context('DRUSH_DRUPAL_SITE_ROOT')would be a better function to use -- presuming it is available here.Comment #2
Vincenzo commentedNice one! I've been looking for that context variable! Are they documented anywhere?
Anyhow, new patch attached. It now works regardless of how the site dir is specified!
I like this one much better.
Comment #3
greg.1.anderson commentedYou shouldn't remove the
drush_get_option('sites-subdir', ...feature, but instead, default to the bootstrapped site if --sites-subdir is not used.Looking at your patch again, I am confused about why DRUSH_DRUPAL_SITE_ROOT would be defined, but DRUSH_DRUPAL_SITE would not be. In other words, without having tested anything, it is my assumption that if the new code works, the existing code should also work as well. If this is not the case, it would be very helpful to know why.
As for documentation on the bootstrap process, see
drush topic docs-bootstrap. The existing documentation does not explain what Drush does in each bootstrap phase; contributions that improve the docs would be most welcome.Comment #4
Vincenzo commentedI removed
drush_get_option('sites-subdir', ...because I noticed that DRUSH_DRUPAL_SITE_ROOT picks that up.Also DRUSH_DRUPAL_SITE is not undefined, it just returns the wrong value, as far as I am concerned.
Let's stick with scenario I described in my post. Let's also assume I run the following commands.
With my patch,
$sites_subdirwill always be set tomysitedir.With the unpatched code,
$sites_subdirwill bemysitedirwith the first three commands, but will bea.mysite.comwith the other two commands.Given that there is a
sites.phptelling Drupal thata.mysite.comis mapped ontomysitedir, I reckon the current behaviour is wrong, and my patch should fix it.Comment #5
Vincenzo commentedComment #6
greg.1.anderson commentedI'm not sure about #4. Sounds like you are sure, but a test case would help convince me.
Comment #7
Vincenzo commentedHi Greg.
Not sure what you are asking me to do :)
If you try and replicate what I explained in the original post and then run the commands in #4 with and without the patch, then you should see what I mean.
Please do tell me if my original post is not detailed enough.
Comment #8
greg.1.anderson commentedI will investigate your issue when I have time; it would take me less time, & I would therefore be able to get to it faster if you added code to tests/siteIntallD6Test.php that failed without your patch, and worked with it.
Comment #9
Vincenzo commentedRight! Will do.
Comment #10
Dublin Drupaller commentedgreat patch Vincenzo. would be great to get this in.
Comment #11
Vincenzo commentedYeah, I still have to write the test in order for this to be accepted. But work is taking all my time.
Comment #12
wamilton commentedA cursory search does not yield any information on running the drush test suite, and there's no 'contributing' section to the docs from the project page, but this should definitely fail without the patch. If not, it's likely a problem with the testing harness or I've grievously misunderstood something.
Comment #13
joestewart commented@wamilton there is a README.txt in the tests/ directory - http://drupalcode.org/project/drush.git/blob/refs/heads/8.x-6.x:/tests/R...
It has information on installing and running phpunit.
You can also run subsets or a single test by using the filter argument like - "phpunit --filter=testSiteContextSetsSubdir ."
Comment #14
wamilton commented@joestewart thanks, I was able to run the tests.
Unfortunately, the patch does not pass with what I consider to be the proper test: omit
--sites-subdirand rely solely on--uri.I am including a patch that adds that test and a re-roll of the submitted patch against 8.x-6.x, since that's where it was initially derived. Setting tags to match.
Comment #15
moshe weitzman commentedLooked briefly at that patch. So does it still honor sites-subdir when provided (assuming no --uri is provided)
Comment #16
Vincenzo commentedI am not sure the test is checking the right thing to be honest, but I might be missing something that wamilton and the others have inferred.
My patch was never proposed to say that
--sites-subdirwas redundant. It was proposed because, insite-install,drush's ability to detect the right site folder was inconsistent across different ways of doing it under particular circumstances. I'll try and explain the scenario a bit better than I did in the past.We have a number of sites in multisite configuration. Let's say that
ls sitesgives us thisThe
defaultfolder is not used.The circumstances I am talking about are to be found in
sites.php:We also have aliases set up for all sites, e.g.
Replace
localwith eitherlive,stageortestand you'll have all the possible aliases that are compiled to target these sites.So far I've set the scenario, and I hope, if I am not mistaken anything, that we all agree that in every circumstance, the site folder for the
example.comsite is alwaysexample.comregardless of whether the site is being accessed from one or the other of all the acceptable URLs mapped to that folder (e.g. www.example.com or com.local.mycompany.it). Same thing holds forexample.netand all other potential sites (all set-up the same).That said, here's a number of ways I could install one of these sites with drush:
With the patch applied,
$sites_subdirwill always be set toexample.com.With the non-patched code,
$sites_subdirwill be set toexample.com(correct) with the first three commands, but will be set tocom.local.mycompany.it(incorrect) with the last two commands.Given that there is a
sites.phptelling Drupal thatcom.local.mycompany.itis mapped onto theexample.comdirectory, I reckon the behaviour of the non-patched code is wrong, whereas the patch brings in the correct behaviour.Unfortunately I am not too sure how to reflect this into a valid test, being quite unfamiliar with
drushinternals.I'll try and have a go now, that I've got some spare time on my hands (part of which I've just burnt to write all this :D).
Cheers,
V
Comment #17
greg.1.anderson commentedThis issue was marked
closed (won't fix)because Drush has moved to Github.If desired, you may copy this bug to our Github project and then post a link here to the new issue. Please also change the status of this issue to
closed (duplicate).Please ask support questions on Drupal Answers.
Comment #18
Vincenzo commentedMoved to a pull request on Github.