It'd be nice if there was self-discovery logic that would be able to smartly figure out the URL of the Drupal installation where drush was installed, so that I could just run:

drush pm install blah blah blah

Rather than

drush -l http://localhost/6x pm install blah blah

I did a var_dump of $_SERVER and it looks like this might not be possible, though...

CommentFileSizeAuthor
#2 drush-fix-notice-239524-2.patch1.02 KBwebchick

Comments

webchick’s picture

Title: Make uri argument optional » Undefined index 'host' error

Oh, I see. It's not required. I just get

Notice: Undefined index:  host in /Applications/MAMP/htdocs/provision_research/sites/all/modules/drush/drush.php on line 94

which cascades into 20,000 errors.

webchick’s picture

StatusFileSize
new1.02 KB

Hrm. Well. This fixes it. No telling if it breaks anything else, tho.

But compare before/after the patch with E_ALL reporting going and you'll see what I mean.

webchick’s picture

Status: Active » Needs review
webchick’s picture

And in case you're too lazy to do that, here's what happens. ;)

Macintosh-97:6x webchick$ php sites/all/modules/drush/drush.php help

Notice: Undefined index:  host in /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php on line 94

Call Stack:
    0.0012   1. {main}() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:0
    0.0012   2. drush_bootstrap() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:20


Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:94) in /Applications/MAMP/htdocs/6x/includes/bootstrap.inc on line 976

Call Stack:
    0.0012   1. {main}() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:0
    0.0012   2. drush_bootstrap() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:20
    0.0018   3. _drush_bootstrap_drupal() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:104
    0.0047   4. drupal_bootstrap() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:185
    0.0137   5. _drupal_bootstrap() /Applications/MAMP/htdocs/6x/includes/bootstrap.inc:928
    0.0144   6. session_start() /Applications/MAMP/htdocs/6x/includes/bootstrap.inc:976


Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:94) in /Applications/MAMP/htdocs/6x/includes/bootstrap.inc on line 976

Call Stack:
    0.0012   1. {main}() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:0
    0.0012   2. drush_bootstrap() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:20
    0.0018   3. _drush_bootstrap_drupal() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:104
    0.0047   4. drupal_bootstrap() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:185
    0.0137   5. _drupal_bootstrap() /Applications/MAMP/htdocs/6x/includes/bootstrap.inc:928
    0.0144   6. session_start() /Applications/MAMP/htdocs/6x/includes/bootstrap.inc:976


Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:94) in /Applications/MAMP/htdocs/6x/includes/bootstrap.inc on line 577

Call Stack:
    0.0012   1. {main}() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:0
    0.0012   2. drush_bootstrap() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:20
    0.0018   3. _drush_bootstrap_drupal() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:104
    0.0047   4. drupal_bootstrap() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:185
    0.0146   5. _drupal_bootstrap() /Applications/MAMP/htdocs/6x/includes/bootstrap.inc:928
    0.0167   6. drupal_page_header() /Applications/MAMP/htdocs/6x/includes/bootstrap.inc:1002
    0.0167   7. header() /Applications/MAMP/htdocs/6x/includes/bootstrap.inc:577


Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:94) in /Applications/MAMP/htdocs/6x/includes/bootstrap.inc on line 578

Call Stack:
    0.0012   1. {main}() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:0
    0.0012   2. drush_bootstrap() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:20
    0.0018   3. _drush_bootstrap_drupal() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:104
    0.0047   4. drupal_bootstrap() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:185
    0.0146   5. _drupal_bootstrap() /Applications/MAMP/htdocs/6x/includes/bootstrap.inc:928
    0.0167   6. drupal_page_header() /Applications/MAMP/htdocs/6x/includes/bootstrap.inc:1002
    0.0168   7. header() /Applications/MAMP/htdocs/6x/includes/bootstrap.inc:578


Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:94) in /Applications/MAMP/htdocs/6x/includes/bootstrap.inc on line 579

Call Stack:
    0.0012   1. {main}() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:0
    0.0012   2. drush_bootstrap() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:20
    0.0018   3. _drush_bootstrap_drupal() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:104
    0.0047   4. drupal_bootstrap() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:185
    0.0146   5. _drupal_bootstrap() /Applications/MAMP/htdocs/6x/includes/bootstrap.inc:928
    0.0167   6. drupal_page_header() /Applications/MAMP/htdocs/6x/includes/bootstrap.inc:1002
    0.0169   7. header() /Applications/MAMP/htdocs/6x/includes/bootstrap.inc:579


Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:94) in /Applications/MAMP/htdocs/6x/includes/bootstrap.inc on line 580

Call Stack:
    0.0012   1. {main}() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:0
    0.0012   2. drush_bootstrap() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:20
    0.0018   3. _drush_bootstrap_drupal() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:104
    0.0047   4. drupal_bootstrap() /Applications/MAMP/htdocs/6x/sites/all/modules/drush/drush.php:185
    0.0146   5. _drupal_bootstrap() /Applications/MAMP/htdocs/6x/includes/bootstrap.inc:928
    0.0167   6. drupal_page_header() /Applications/MAMP/htdocs/6x/includes/bootstrap.inc:1002
    0.0169   7. header() /Applications/MAMP/htdocs/6x/includes/bootstrap.inc:580

So um. Yeah. Would be nice if it wouldn't do that. ;)

owen barton’s picture

Title: Undefined index 'host' error » Make uri argument optional
Status: Needs review » Active

I don't think there is a way to do it using $_SERVER from the command line, because Apache (which normally provides most of the $_SERVER variables) is not involved in the request at all.

You can do this in a fashion right now by adding the 'l' parameter to a drushrc.php file in the sites/mysitename.com directory (or any directory that you live in when you work on that site).

The way I think this *could* be done in a smarter way (and have been meaning to try for some time) is to check the current directory, and also each parent directory (in turn) for a settings.php, and then to try using the name of *that* directory as the domain, if no specific domain 'l' parameter is passed in from the command line. This way, you should be able to run drush from anywhere inside a sites directory (e.g. from a mysitename.com/modules/cck) without needing to specify 'l' at all.

The 2 special cases of 'default' and 'all' would need to be checked at all. I think 'default' should work fine (since it would use that site if you accessed Drupal through http://default), but 'all' would need a special check I think (probably just fail with a helpful error message for now).

moshe weitzman’s picture

Just set your l param in a drushrc.php and you never have to think about it again. takes 10 seconds. i'll look at patches for this, but my pain is long gone on this topic.

eyecon-1’s picture

The simplest and most flexible solution (for me) is a .bashrc function that includes a "for" loop. No sense encumbering a module.

moshe weitzman’s picture

Category: bug » feature
Dan_Hoey’s picture

Title: Make uri argument optional » Make uri argument optional or make it required
Category: feature » bug

The "documentation" for drush is the output from drush help, and that says that the -l <uri>; option is only needed in multi-site environments. Yet this obscure error message always appears if you omit the option, even for drush help. I've got drush 5.x-1.3, and I don't see the cascading, but even one error message is a bug if there's no error.

Dan_Hoey’s picture

Title: Make uri argument optional or make it required » Make uri argument optional
Version: » 5.x-1.x-dev

On further examination, I find that moshe has applied the patch in drush-7.x-1.x-dev and drush-6.x-1.x-dev. So the bug is only in drush-5.x-1.x-dev, which doesn't have webchick's patch.

moshe weitzman’s picture

Category: bug » feature

Well, you probably don't have settings.php in the default directory. Thats what drupal does by default. If you stary from that, than you need to specify -l. You can specify it in drushrc.php so you don't need to ever think about it.

Feel free to suggest better wording in the docs.

Dan_Hoey’s picture

I've got ./sites/default/settings.php, is that what you mean? I still don't see how settings.php could make

define('DRUSH_URI', drush_get_option(array('l', 'uri'), FALSE));

(in ./modules/drush/drush.php in drush-5.x-1.3) set DRUSH_URI to something that makes

$drupal_base_url = parse_url(DRUSH_URI);

have a 'host' component.

moshe weitzman’s picture