Problem/Motivation

We use Drupal's multi-site functionality to version control different server environments settings and drush runtime configurations separately.

sites/example.com/settings.php
sites/example.com/drushrc.php 
sites/dev.example.com/settings.php
sites/dev.example.com/drushrc.php
sites/example.local/settings.php
sites/example.local/drushrc.php

We have been using drushrc.php in the Drupal root, to specify which environment to load via the $options['uri'] = "http://example.local';. This would allow us to execute typical drush commands inside our multi-site (server environment) configuration, without having to specify a default --uri option with every command.

This is no longer possible with Drush 5, because it only loads the drushrc.php file in the Drupal root once Drupal/Drush has been bootstrapped with an appropriate --uri option.

Proposed resolution

Move the drushrc.php out of the Drupal root folder, to sites/all/drush/drushrc.php, where the $options['uri'] is loaded appropriately. This file may then be symbolically linked from one of the multi-site's drushrc.php files, to load the appropriate uri, depending on the server environment.

Original report by jwilson3

I just updated drush from a git pull on the master branch... and to my dismay the css-js (which was awesomely recently renamed from css+js ;-) simply does not work any more.

Executing drush cache-clear from any location inside a drupal_root folder, results in the following options:

~user@web:~/drupal_root $ drush cache-clear
Enter a number to choose which cache to clear.
 [0]  :  Cancel   
 [1]  :  all      
 [2]  :  drush    
 [3]  :  registry 

However, if I specify the --uri option, it offers a plethora more options:

~user@web:~/drupal_root $ drush cache-clear --uri=example.com
Enter a number to choose which cache to clear.
 [0]   :  Cancel         
 [1]   :  all            
 [2]   :  drush          
 [3]   :  theme-registry 
 [4]   :  menu           
 [5]   :  css-js         
 [6]   :  block          
 [7]   :  module-list    
 [8]   :  theme-list     
 [9]   :  registry       
 [10]  :  views          

My Drupal / Drush configuration runs off a symbolic link to a specific site folder, based on the server environment I'm currently on (this has worked fine in the past, but i dont know if this is the cause for not finding the drushrc.php in the drupal root or what):

~/drupal_root/drushrc.php  --> symbolic link to ~/drupal_root/sites/example.com/drushrc.php

Other core drush commands work flawlessly, and don't seem to show any symptoms of the missing --uri option.

Comments

jwilson3’s picture

Note, drush cache-clear drush has no effect on this issue, the extra options are still missing.

jwilson3’s picture

More debugging:

If I replace the default sites/default folder provided by Drupal with a symbolic link to my site folder, the cache-clear options are found.

ie, this works:

# sites/default --> symlink to sites/example.com
#
# drush cc 
Enter a number to choose which cache to clear.
 [0]   :  Cancel         
 [1]   :  all            
 [2]   :  drush          
 [3]   :  theme-registry 
 [4]   :  menu           
 [5]   :  css-js         
 [6]   :  block          
 [7]   :  module-list    
 [8]   :  theme-list     
 [9]   :  registry       
 [10]  :  views    
jwilson3’s picture

The real issue here is that drushrc.php is apparently no longer being sourced from the Drupal root folder, as it was in drush 4.x

this excerpt from examples/example.drushrc.php explains the issue...

Configuration files are loaded in the reverse order they are
shown above.  All configuration files are loaded in the first
bootstrapping phase, but the configuration files stored at
a Drupal root or Drupal site folder will not be loaded in
instances where no Drupal site is selected.  However, they
_will_ still be loaded if a site is selected (either via
the current working directory or by use of the --root and
--uri options), even if the Drush command being run does
not bootstrap to the Drupal Root or Drupal Site phase.
Note that this is different than Drush-4.x and earlier, which
did not load these configuration files until the Drupal site
was bootstrapped.

We have been using drushrc.php in the drupal root, to *specify* which environment to load via the $options['uri'] = "http://example.local';.

We're looking into another way to solve this, but any suggestions are recommended. Thanks.

jwilson3’s picture

Issue summary: View changes

Fixed the long form --uri (was inadvertently specified as --url) I usually use the shorthand version.... -l (dash L).

jwilson3’s picture

Title: drush cache-clear missing options when --uri option not specified » drushrc.php in Drupal root cannot be used to specify --uri option

For the moment, the only solution is to symlink sites/default/settings.php to the proper settings file in the multi-site folder.

eg

sites/default/settings.php --> symlink to: sites/example.local/settings.php (on local environment)
sites/default/settings.php --> symlink to: sites/stage.example.com/settings.php (on staging environment)
sites/default/settings.php --> symlink to: sites/example.com/settings.php (on production environment)

Anyone know of another way to do this?

moshe weitzman’s picture

Category: bug » support
Status: Active » Fixed

sites/all/drush replaced drupal root as location for config/alias/command files

greg.1.anderson’s picture

Title: drushrc.php in Drupal root cannot be used to specify --uri option » drushrc.php is no longer sourced from Drupal root; sites/all/drush is the new location

Do you think we should help folks out by printing a warning if we find a drushrc.php file at the Drupal root? A lot of people upgrading from Drush 4 will probably encounter this.

greg.1.anderson’s picture

Issue summary: View changes

Create summary from comment #3 excerpt, to better explain the real issue.

jwilson3’s picture

Issue summary: View changes

Added Proposed Solution, and elaborated on Problem/Motivation.

jwilson3’s picture

Greg,

I've moved my symbolically linked drushrc.php out of drupal root into sites/all/drush and this worked perfectly. I've added this to the Proposed Solution above.

However, in my testing I wasn't actually ever able to get a drushrc.php to even *load* from the Drupal root with drush 5, even after putting the proper uri in sites/all/drush/drushrc.php

moshe weitzman’s picture

@Greg - I think the existing Change Notice is sufficient. I'd not take the file_exists() hit on every request.

greg.1.anderson’s picture

@jwilson3: you should be able to re-enable the Drupal root as an install location for drushrc.php by setting $options['config'] = 'path'; in a drushrc.php file that is being loaded. If you use the one in sites/all/drush/drushrc.php, setting a path relative to __FILE__ should work. Seems easier to just move the file to the new location, though.

jwilson3’s picture

you should be able to re-enable the Drupal root as an install location for drushrc.php by setting $options['config'] = 'path'; in a drushrc.php file that is being loaded.

Right, ok... except example.drushrc.php claims that drushrc.php would be loaded in the drupal root, if --root or --uri would be specified:

...the configuration files stored at a Drupal root or Drupal site folder will not be loaded in instances where no Drupal site is selected. However, they _will_ still be loaded if a site is selected (either via the current working directory or by use of the --root and --uri options).

but this is clearly not the case.

So, ideally, there needs to be two changes:

- have Drush 5 check for drushrc.php in a Drupal root, even though it doesnt source the file, and provide a deprecated warning.
- update example.drushrc.php to explain properly how to get drushrc.php to be sourced from a Drupal root.

thoughts?

greg.1.anderson’s picture

Component: Core Commands » Documentation
Category: support » task
Status: Fixed » Active

Yes, we need to update the documentation here; however, per #8, we are not going to provide a warning if a config file is found in the old location.

jwilson3’s picture

Ah, my bad. I missed comment #8.

jwilson3’s picture

Status: Active » Needs review
StatusFileSize
new2.46 KB

Here's a patch for documentation examples/example.drushrc.php.

Also, I noticed that the column wrap in that file is not anywhere close to 80 columns, and sometimes varies widely. I wouldn't mind adjusting that and providing a patch, as long as it could get applied reasonably quickly, so as not to have to continuously re-roll.

UPDATE: There were two whitespace cleanups that snuck into the patch, because my editor is set to remove them by default. I can remove if needed.

greg.1.anderson’s picture

Status: Needs review » Reviewed & tested by the community

Fixing whitespace is a good feature. Docs update looks good; thanks.

I'll probably have time to commit this patch, and any provided rewrapping patch, later this afternoon.

jwilson3’s picture

Here's a general doc cleanup of the example.drushrc.php

I stumbled across one thing... there is an example for options to `drush core-cli`, but that command appears to have been removed from Drush 5 (is that correct?).

After this patch is applied I'd also like to reorganize a few of the entries and group them together more logically, for example, by putting the general Drush global options at the top, and then more specific but shared common commands' options below....

UPDATE:
e.g. --package-handler seems out of place between the --default-major and the --include options, which both apply to Drush's bootstrap itself.

^ that was a poor example.. heres a better one:

--self-update, --default-major, --package-handler which apply to download and update commands, seem out of place between the --config and the --include options, which apply to Drush's bootstrap itself. Also, the -v option could be moved up to the top along side -l and -r.

jwilson3’s picture

Fixed two more tiny mistakes in the first couple sentences.

greg.1.anderson’s picture

Status: Reviewed & tested by the community » Fixed

Looks much better; thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Syntax error