Closed (fixed)
Project:
Drush
Component:
PM (dl, en, up ...)
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
24 Oct 2010 at 04:24 UTC
Updated:
15 Dec 2010 at 21:00 UTC
Jump to comment: Most recent file
Currently, in multi-site environments, when you want to download some projects for a specific site you must:
- create a config file for each site with the respective command specific option, or
- add to each alias the respective 'command-specific' item, or
- use the --destination option every time.
This patch tries to avoid this.
| Comment | File | Size | Author |
|---|---|---|---|
| #31 | drush-951026.patch | 2.57 KB | jonhattan |
| #29 | drush-951026.patch | 2 KB | jonhattan |
| #25 | drush_dl_destination_3.patch | 2.06 KB | luchochs |
| #15 | drush-951026.patch | 939 bytes | jonhattan |
| #11 | drush_dl_destination_2.patch | 2.21 KB | luchochs |
Comments
Comment #1
luchochs commentedI will create a new issue for the code that does not correspond to this one.
Comment #2
moshe weitzman commentedWe discussed the current behavior in #433838-8: drush dl attempts download to default when nothing specified and its replies. Pls review that and see if this patch is still desired.
Comment #3
luchochs commentedMoshe, the proposal here is different.
Which is avoided by the suggested patch is, for example, this:
After applying the patch:
Sorry if I was not descriptive previously.
Update: Most comprehensive example.
Update2 [comprehensive != comprehensible (Spanish)]: Most understandable example.
Comment #4
jonhattanWhen running drush dl from sites/example.com you get a different result than when running drush @example.com from other path (if sites/example.com/modules exists).
Forcing the usage of sites/example.com/{modules,themes}, even creating the directory if it doesn't exist could be implemented as an option to set in drushrc.
@luchochs: your patch is conceptually wrong. pm_dl_destination_lookup() is called several times by pm_dl_destination().
Comment #5
luchochs commentedJonnhattan:
I can't reproduce that.
According to my tests, 'several' does not make sense in that sentence.
Comment #6
jonhattanTo confirm «When running drush dl from sites/example.com you get a different result than when running drush @example.com from other path (if sites/example.com/modules exists).»
It does.
Comment #7
ilo commentedsubscribing.
Comment #8
luchochs commentedYou must add the 'uri' item to your alias, i.e.,
'uri' => 'd6'.Regarding the call to the
pm_dl_destination_lookup()function, could you explain in what condition/context is called several times? Thanks.Comment #9
jonhattanIndeed I have
'uri' => 'http://d6',but this is not the cause.Responses are here: http://drupalcode.org/viewvc/drupal/contributions/modules/drush/commands...
cwd is used to find a destination. If you are running
drush dl zenfrom within the site directory, it will be placed in sites/example.com/modules only if modules/ exists. If running from outside the site directory, it will use sites/all/modules, even if using @example.Comment #10
moshe weitzman commentedI think the issue is that folks are naturally lazy and changing your cwd is too much work and adding --destination is too much work. they just want to drop modules in site specific directory if it exists and cwd does not suggest otherwise (e.g. you are in drupal root). seems reasonable at first thought.
Comment #11
luchochs commentedThat's the idea. A simple and practical way to tell Drush that there's a site that requires specific projects; just creating the appropriate (and conventional) directory.
In my tests (results below) the
pm_dl_destination_lookup()function was called only one time whenever thepm-downloadcommand was in use and cwd did not behave in an unexpected way.Probably someone else can test this too.
New version of the patch with a bit of documentation in accordance with the code, and without special handling for the Theme engines (disuse nowadays).
Comment #12
luchochs commentedFor those who are interested in this: #11's patch still applies correctly against HEAD.
Comment #13
greg.1.anderson commentedConceptually I am okay with this patch. It follows the same pattern as the existing test for 'contrib'. The only think that is odd is that the path printed is an absolute path for all existing cases, but is a relative path for the new locations.
It would be better to prepend $drupal_root to conf_path() for consistency. Also, I have a slight preference for following the style of the $contrib check, and assign the variable outside of the 'if' statement.
With those changes, I think this could be committed.
Comment #14
luchochs commentedGood news for those who work daily in multisite environments and prefer to take advantage of site-alias feature. New patch shortly.
Comment #15
jonhattanAs I mentioned in previous comments luchochs approach is not the way to solve this.
Attached is a clean way to fix this. I'm not very familiar with sitealias and haven't found a function to test if drush was invoked with @site.
and here's my test:
In addition, as I mentioned in #4 when using a sitealias would be oportune to create the directory if it doesn't exist. In fact you're telling drush to download a project to the site dir.
Comment #16
greg.1.anderson commentedThis patch is mildly problematic, regardless of approach.
Moshe said:
It seems odd that if the user's cwd is the drupal root that the target of dl would change. If the user explicitly made a 'sites/mysite/modules' directory, then drush should use that. The user might be at the drupal root 'by accident', as this is a common location to be. On the other hand, if the user wants some modules to be at sites/all and some to be at sites/mysite/modules, well, I'm not sure that there's an easy way to support that besides using --destination. Prompt?
Anyway, I never use site-specific module directories, though, so at the end of the day I'm indifferent which way this goes.
Regarding #15,
(count(drush_get_context('alias')))is not a good way to check to see if an alias is being used. By the current implementation, which uses lazy-evaluation to load alias definitions as needed, it happens at the moment that the alias context will be empty when there is no alias reference. However, this was not true in the past and might not be true in the future; the alias code might pre-load something and stuff it in the 'alias' context prior to alias evaluation.The alias system is designed to be equivalent to using options, so I think that perhaps a better test would be to see if --root has been defined. If it has, then cwd will not affect bootstrapping, so you might as well treat this case the same as the @sitealias case.
Comment #17
jonhattanI just wanted to outline a clean way to implement luchochs proposal but I'm fine with cd'ing or --destination.
Other different approach is --use-site-dir. This is not conflictive and perhaps the only option to not mark the issue as won't fix.
One more approach (up to users): implement a custom
hook_drush_pm_download_destination_alter()to set the install location (see @pm_drush_pm_download_destination_alter() for reference).I agree it is problematic to use @alias. I suppose there're also problems with built-in, remote and/or group aliases.
Some tests:
^^ problematic: current implementation will not use site-specific-folder and it's not clear what the user wanted by providing @alias.
^^ here there is no incompatibility with current behaviour. It can be considered as desirable: you ask drush to download to a given site by providing the alias.
Comment #18
greg.1.anderson commentedI like
--use-site-dir. Users who want drush to work as in #11 can set$options['use-site-dir'] = TRUE;in their drushrc.php.Comment #19
luchochs commentedJonhattan, you're working on a patch for this issue? Let me know please.
Comment #20
jonhattanno, i'm not working on this.
Comment #21
luchochs commentedThanks for the prompt response, I'll see if I can do something in the matter.
P.S.: Greg, I assumed that you aren't working on a patch here, if I'm mistaken let me know please.
Comment #22
greg.1.anderson commentedPatches welcome; I'll review what is submitted.
Comment #23
luchochs commentedIt seems appropriate to add the following in case anyone read my previous comment and it stops his desire to take this into HEAD:
At the moment I'm not working on this, if this changes I will notify.
Comment #24
luchochs commentedComment #25
luchochs commentedNew approach.
Pre-patch:
Post-patch:
Attempts 1,4,5 & 6 don't vary.
Comment #26
greg.1.anderson commentedI think we should require a flag (e.g. --use-site-dir) before allowing sites/sitename/modules to be used. If --use-site-dir is specified, it should take priority and create sites/sitename/modules if it does not exist. The 'contrib' check should still be done.
Comment #27
luchochs commentedThe flag once the directory has been created is no longer needed, but yes, is useful (maybe
--make-......is more representative).Regarding 'contrib', the check is still done (the comment need a fix).
Comment #28
greg.1.anderson commentedPer #16, we must consider the situation where someone wants some of their modules in the site-specific directory, and some of their modules in sites/all/modules. Today you can use --destination to select. Any patch that changes current behavior should be more convenient without removing options, ergo --use-site-dir. If the site-specific directory exists, but --use-site-dir is not specified, then the project should be downloaded to sites/all/modules.
Comment #29
jonhattanSumarizing:
1- we want to preserve current behaviour and
2- add a new flag --use-site-dir that will force to use the site specific module/theme directory if bootstrap level >= SITE and
3- will create that directory if it does not exist.
Comment #30
luchochs commented--use-site-diris a good idea.Other thoughts:
1.- We need to update the current behavior to ensure conformity with the sitealias age.
2.-
pm_dl_destination_lookup()has a parameter to create the directory, we might take advantage of it.3.-
pm_dl_destination()'s$site_rootis a good reference.Comment #31
jonhattanNew patch takes advantage of $create argument to pm_dl_destination_lookup()
Comment #32
luchochs commented#31 looks & works good to me.
Comment #33
luchochs commentedProductive exchange of ideas, really.
Comment #34
jonhattancommited.