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.com

I 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

Comments

greg.1.anderson’s picture

Status: Active » Needs work

This 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). Perhaps drush_get_context('DRUSH_DRUPAL_SITE_ROOT') would be a better function to use -- presuming it is available here.

Vincenzo’s picture

StatusFileSize
new696 bytes

Nice 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.

greg.1.anderson’s picture

You 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.

Vincenzo’s picture

I 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.

$ drush si my-profile -l mysitedir
$ drush si my-profile --sites-subdir=mysitedir
$ cd /path/to/sites/mysitedir && drush si my-profile
$ drush si my-profile --uri=http://a.mysite.com
$ drush @mysite.a si my-profile 

With my patch, $sites_subdir will always be set to mysitedir.
With the unpatched code, $sites_subdir will be mysitedir with the first three commands, but will be a.mysite.com with the other two commands.

Given that there is a sites.php telling Drupal that a.mysite.com is mapped onto mysitedir, I reckon the current behaviour is wrong, and my patch should fix it.

Vincenzo’s picture

Status: Needs work » Needs review
greg.1.anderson’s picture

I'm not sure about #4. Sounds like you are sure, but a test case would help convince me.

Vincenzo’s picture

Hi 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.

greg.1.anderson’s picture

I 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.

Vincenzo’s picture

Right! Will do.

Dublin Drupaller’s picture

Version: » 7.x-5.7

great patch Vincenzo. would be great to get this in.

Vincenzo’s picture

Yeah, I still have to write the test in order for this to be accepted. But work is taking all my time.

wamilton’s picture

Version: 7.x-5.7 » 7.x-5.x-dev
StatusFileSize
new1.61 KB

A 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.

joestewart’s picture

@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 ."

wamilton’s picture

Version: 7.x-5.x-dev » 8.x-6.x-dev
Status: Needs review » Needs work
StatusFileSize
new918 bytes
new811 bytes

@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-subdir and 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.

moshe weitzman’s picture

Status: Needs work » Postponed (maintainer needs more info)

Looked briefly at that patch. So does it still honor sites-subdir when provided (assuming no --uri is provided)

Vincenzo’s picture

I 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-subdir was redundant. It was proposed because, in site-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 sites gives us this

all
example.com
example.net
default

The default folder is not used.

The circumstances I am talking about are to be found in sites.php:

<?php

$sites['example.com'] = 'example.com'; // Live domain.
$sites['www.example.com'] = 'example.com'; // Live domain.
$sites['com.live.mycompany.it'] = 'example.com'; // Alternate live domain (for admin access, or similar).
$sites['com.stage.mycompany.it'] = 'example.com'; // Stage domain.
$sites['com.test.mycompany.it'] = 'example.com'; // Integration/QA domain.
$sites['com.local.mycompany.it'] = 'example.com'; // Local development domain.

$sites['example.net'] = 'example.net'; // Live domain.
$sites['www.example.net'] = 'example.net'; // Live domain.
$sites['net.live.mycompany.it'] = 'example.net'; // Alternate live domain (for admin access, or similar).
$sites['net.stage.mycompany.it'] = 'example.net'; // Stage domain.
$sites['net.test.mycompany.it'] = 'example.net'; // Integration/QA domain.
$sites['net.local.mycompany.it'] = 'example.net'; // Local development domain.

We also have aliases set up for all sites, e.g.

$aliases["local.project.com"] = array (
  'root' => '/var/www/drupal-root',
  'uri' => 'com.local.mycompany.it',
  'path-aliases' => 
  array (
    '%site' => 'sites/example.com/',
  ),
  '#name' => 'local.project.com',
  '#file' => '/var/www/drupal-root/sites/all/drush/local.project.aliases.drushrc.php',
);

$aliases["local.project.net"] = array (
  'root' => '/var/www/drupal-root',
  'uri' => 'net.local.mycompany.it',
  'path-aliases' => 
  array (
    '%site' => 'sites/example.net/',
  ),
  '#name' => 'local.project.net',
  '#file' => '/var/www/drupal-root/sites/all/drush/local.project.aliases.drushrc.php',
);

Replace local with either live, stage or test and 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.com site is always example.com regardless 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 for example.net and 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:

$ drush si my-profile -l example.com
$ drush si my-profile --sites-subdir=example.com
$ cd /path/to/sites/example.com && drush si my-profile
$ drush si my-profile --uri=http://com.local.mycompany.it
$ drush @local.project.com si my-profile 

With the patch applied, $sites_subdir will always be set to example.com.
With the non-patched code, $sites_subdir will be set to example.com (correct) with the first three commands, but will be set to com.local.mycompany.it (incorrect) with the last two commands.

Given that there is a sites.php telling Drupal that com.local.mycompany.it is mapped onto the example.com directory, 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 drush internals.
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

greg.1.anderson’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)
Issue tags: +Needs migration

This 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.

Vincenzo’s picture

Status: Closed (won't fix) » Closed (duplicate)

Moved to a pull request on Github.