When bootstraping only to DRUSH_BOOTSTRAP_DRUPAL_SITE, drush quickly includes all command files from the 'modules' directory, favoring speed over accuracy. This has the happy side effect of showing help for drush commands that appear in disabled modules (perhaps giving the user even more reason to enable them :> ).

Unfortunately, where install profiles are concerned, only 'profiles/default/modules' is searched, as it is too early in the bootstrap process to call variable_get to find out which install profile is active. This means that if you have an install profile that includes, say, the features module, you will never see any of the drush feature commands in drush help. Very unhappy.

This patch expands the search to grab every command file found anywhere in the 'profiles' directory. If you happen to have two profiles with the same drush command file, drush will already correctly include only one of them. If they happen to be different versions of the same command file, well, maybe your help will be off, but this situation is probably rare, and still preferable to not having any help at all.

Comments

greg.1.anderson’s picture

The patch at 827888-#9 has now been changed to read:

        // Too early for variable_get('install_profile', 'default'); Just use default.
        $searchpath[] = "profiles/default/modules";

I think #0 is a reasonable compromise.

moshe weitzman’s picture

@Greg - I had to look closely to see what is going on. 827888-#9 changed the CONFIGURATION phase, not the SITE phase, which is what you propose to change here. Search for 0c4a04e6 at http://drupalcode.org/project/drush.git/blame/HEAD:/includes/command.inc to see what I mean.

This sounds like a reasonable change. Can you share your use case, or other use cases you have in mind?

moshe weitzman’s picture

From the title it sounds like you want this for help command. Try to add $conf['install_profile'] = PROFILENAME to your settings.php and see if help gets better for you. As noted at #827888: Drush not picking up commands from modules located in an install profile in the help message?, site-install should be expanded so it writes this to bottom of settings.php.

greg.1.anderson’s picture

Title: drush help ignores modules in install profiles » set install profile in settings.php during site-install, and make it easier for drush help to find commandfiles
Status: Needs review » Needs work

Already did #4 + an improvement on the original patch; will post it shortly. Thanks.

greg.1.anderson’s picture

Status: Needs work » Needs review
StatusFileSize
new2.58 KB

This patch does two things.

  1. site-install adds $conf['install_profile'] if needed. This will make the DRUPAL_CONFIGURATION bootstrap check just that install profile for commandfiles.
  2. If 'install_profile' is not set, then drush help (or any other command that bootstraps to DRUPAL_CONFIGURATION) will look for commandfiles in all profiles. Any command that bootstraps to DRUPAL_SITE and no farther will look for commandfiles in all profiles.
moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

I kind of think we should write $conf['install_profile'] unconditionally. That will help make folks aware that this feature exists and distros will encourage folks to use it. Otherwise, looks RTBC.

greg.1.anderson’s picture

Status: Reviewed & tested by the community » Fixed

Committed without the suggestion in #7; I'm worried that unconditionally writing this to settings.php will cause install_profile configurations to pile up on re-installs. Hm, maybe this is also a problem when an install profile is specified. Re-open to discuss.

moshe weitzman’s picture

Status: Fixed » Active

Though I don't mind the pile up, we're going to get bug reports from the fastidous masses. i now agree that we should conditionally write is, just like what you had before. we can ignore the pile up problem for custom profiles until a better idea comes along.

greg.1.anderson’s picture

If it wouldn't cause environment pollution for the site install, I could try doing an include on settings.php, and check to see if install_profile is already defined in $conf. Since this is the settings.php that will be loaded, it should be safe, so long as we include it after we write $db_url. Need to check if Drupal uses include_once or include when it pulls in settings.php.

moshe weitzman’s picture

I'm worried that someone's settings.php will rely on bootstrap.inc being loaded. Lets not include() settings.php

moshe weitzman’s picture

Maybe we should just do


$contents = file_get_contents('settings.php');
if (strpos('$conf['profile']', $contents) === FALSE) {
  // Append $conf['profile']
}

greg.1.anderson’s picture

Assigned: Unassigned » greg.1.anderson
moshe weitzman’s picture

It looks like were writing install_profile only for D6 sites and only when settings.php did not already exist. I just committed a fix so we write for all Drupal versions and we try to append when settings.php already exists but has no install_profile specified (uses technique from #12 .

greg.1.anderson’s picture

Status: Active » Needs review

Anything left to do here?

moshe weitzman’s picture

Status: Needs review » Fixed

Nope, forgot to mark Fixed with #14.

Status: Fixed » Closed (fixed)

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

chx’s picture

Priority: Normal » Critical
Status: Closed (fixed) » Active

This breaks Drupal 8 testing. I need to remove manually the profile from settings.php.

moshe weitzman’s picture

Priority: Critical » Normal

Where does D8 record the profile that was used? WHats the CMI name?

greg.1.anderson’s picture

Title: set install profile in settings.php during site-install, and make it easier for drush help to find commandfiles » Install profile should not be written to settings.php during site-install for Drupal version 8+
Priority: Normal » Critical

Is there something else that could be done for D8, or does the profile information simply need to be left out?

moshe weitzman’s picture

Priority: Critical » Normal
Status: Active » Postponed (maintainer needs more info)

Could you describe exactly what the failure is when writing this to D8? I am not seeing a problem.

chx’s picture

Sure, try to install minimal and run a test.

chx’s picture

To elaborate, because you force the install profile to be minimal, testing will give you some notices at least (some tests warnings / fatal) because it will try to operate on minimal profile when that is not actually enabled...

moshe weitzman’s picture

Status: Postponed (maintainer needs more info) » Active

I don't quite buy "because you force install_profile to be minimal". Settings.php has nothing to do with the site-under-test. $databases refers to the parent site, config_directories refers to the parent site, etc. Simpletest should be injecting all that it needs into the site-under-test, including the install_profile. This is yet another leakage from parent to site-under-test. I'll probably fix this in Drush, but it is a Simpletest bug.

chx’s picture

Simpletest can't help that $conf overrides are stronger than the variable it sets...

chx’s picture

And I bet that there's a problem with Drupal 7 + testing too just noone does that any more :D

Volx’s picture

Version: » 7.x-5.8

I wasn't testing but still ran into an issue with this behavior of Drush on Drupal 7 that gave me a headache.

When doing a reinstall with drush, the settings.php cannot be altered because it has been set to read-only after the previous install, which usually is fine. But when I change the install profile in one of those reinstalls, the $conf[install_profile] line will stay in settings.php there overriding the variables table which has the correct value and completely messing up the site. It is an easy fix if you know what's going on, but a pita if you don't, as that behavior of Drush is totally unexpected.

Drush shouldn't mess with settings.php for purely cosmetic reasons.

greg.1.anderson’s picture

Version: 7.x-5.8 » 8.x-6.x-dev
Assigned: greg.1.anderson » Unassigned

Update version & unassign.

moshe weitzman’s picture

Reinstalling a different profile is very much an edge case. Drush needs to know what profile is in use in order to find commanfiles and such, early in the bootstrap. We don't do this for "cosmetic" reasons.

As of today, drupal_get_profile() still does a variable_get(). See http://api.drupal.org/api/drupal/core%21includes%21common.inc/function/d.... Once this is in CMI, we might be able to stop writing to settings.php for D8.

chx’s picture

Note: this still breaks testing.

moshe weitzman’s picture

Simpletest can't help that $conf overrides are stronger than the variable it sets...

Simpletest sets up a whole child Drupal. Surely it could inject whatever environment it needs. After all, it injects a db_prefix despite that not existing in settings.php. It could similarly inject an install_profile.

I guess Drush could use its own variable instead of clashing with 'install_profile'

chx’s picture

> It could similarly inject an install_profile.

It's only now it can -- but it would require an override settings.php which does nothing but unsets the $conf['install_profile']. Merely doing a variable_set is not enough because $conf wins over variable_get. (And CMI for that matter)

moshe weitzman’s picture

@chx - simpletest could inject the db_prefix injection there too. not sure if that would be better or not.

moshe weitzman’s picture

Status: Active » Needs review

Here is a patch to change the variable name that we write and read to drush_install_profile so there is no conflict with drupal's install_profile variable.

However, I've just thought of an alternative which is for us to drush_cache_set() the current install profile for a given site. This would be analogous to our commandfile cache for a given site. We would need to figure out where we put the write to cache. I suppose we could do the following during FULL BOOTSTRAP. It would add a cache read for every request though.

if (!drush_cache_get('install_profile') {
  drush_cache_set('install_profile', $install_profile)
}
moshe weitzman’s picture

StatusFileSize
new2.58 KB

Here is the patch I mentioned above, though we might not want it.

A drush_cache_set() approach would work for all sites, not just those whose profile happens to get written to settings.php

moshe weitzman’s picture

StatusFileSize
new2.58 KB

OK, here is the drush_set_cache() approach that implements what I mentioned. Feedback or questions are welcome.

1. No more writing of $conf['install_profile'] in site-install
2. During full bootstrap, we check the drush cache for this site's install_profile. If not present, we drush_cache_set() it. If present, we do a correctness check and re-cache the value in the unlikely event that the profile has changed (e.g. site got re-installed). This slows us a down a little but I think I'm OK with it.
3. And now the whole point, we read the install_profile during SITE bootstrap phase and load commandfiles from only the right profile. We can now do this for all sites, not just the ones that wrote install_profile in their settings.php

Todo: the cid for the install_profile needs to be made site specific. It is currently the same for all your sites which share a drupal major version. That's not good. Help wanted.

moshe weitzman’s picture

In case it isn't clear, the extra wrk I am proposing would be a fix for some problems reported in #1529968: Don't reload commands that have already been loaded..

I'm not sure how I want to proceed here.

greg.1.anderson’s picture

1. There is no call to drush_cache_set() in #36. Is that the right patch?

2. Could the full path to the site folder (directory holding settings.php) be included in the cid to make it unique per cache? This should be known at this point in the code, I think.

moshe weitzman’s picture

StatusFileSize
new5.52 KB

Oops. Here is right patch. It does not yet have Greg's fine suggestion regarding a better cid.

moshe weitzman’s picture

We should decide if we want to go with #35 or #39 or none of the above.

greg.1.anderson’s picture

StatusFileSize
new1.75 KB
new6.86 KB

This looks fine to me; although I have not tested it much, it seems it should work. Here's a patch with the selected site path included in the cid, plus a minor typo fix.

moshe weitzman’s picture

Status: Needs review » Fixed

Committed. Thanks.

FYI, the patch in #41 did not apply for me with git appy but I was able to freshen it up per the interdiff.

Status: Fixed » Closed (fixed)

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