New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stop by bootstrap to DRUPAL_ROOT when searching for commandfiles #1490
Stop by bootstrap to DRUPAL_ROOT when searching for commandfiles #1490
Conversation
I'm a bit surprised that this is needed. During preflight, we honor any --root thats provided so we should be able to find this commnadfile then (i.e. DRUSH_BOOTSTRAP_DRUSH). Are you providing --root or are you relying on Drush to discover the root? Maybe this is needed in the discovery case. |
I'm running from the drupal root. Also tested with an alias and --root with no success:
As I understand it, in DRUSH_BOOTSTRAP_DRUSH, the drupal version is unknown, and |
The commandfile is excluded here because drush doesn't know the drupal version at preflight: |
Thanks for figuring that out. I think the PR makes sense. I'd like to hear @greg-1-anderson opinion. I'm not sure about the full repercussions for adding another phase to this array. |
Okay, here is what is going on. The main reason that Drush skips past bootstrap levels like this is so that we can decide whether to look for commandfiles the slow way -- only in enabled modules -- or the fast way -- in all modules that are available, enabled or not. So, under normal circumstances, we find a global Drush command, and then we bootstrap to whatever level it says we should bootstrap to, and then we look for additional commandfiles, so that they can hook our command if they want. We do the fast or slow version based on how far the command wants to bootstrap. This stops us from considering commandfiles in disable modules. I haven't tried this patch yet, but it seems to me that what is going on is that, with this change, we fail to find a global commandfile, then we bootstrap to DRUSH_BOOTSTRAP_DRUPAL_ROOT (new with this patch), so we now know the version of Drupal we are running. I would expect that we still would not find your commandfile, because DRUSH_BOOTSTRAP_DRUPAL_ROOT does not search for commandfiles in modules. At this point, I would expect that Drush would try to bootstrap to DRUSH_BOOTSTRAP_DRUPAL_FULL. I'd think that at this point bootstrap would fail, and you'd be done with an error, before your commandfile is found. Does it instead bootstrap only as far as it can for the site, and then grab your commandfiles? If that is the case, then does it also allow you to run commandfiles in disable modules? I think in some instances, we should allow commandfiles in disabled modules to run. "generate" type commandfiles, for example, are often fair game, especially for themes ("make me a new subtheme of this contrib base theme"). Themes currently work differently than modules. Devel's fn-view and fn-hook are other examples that could be available even when devel is not enabled. I think that before we commit this patch, we should decide what we want the behavior of commandfiles in disabled modules to be. I think that bootstrapping was changed to work this way because there were some examples (which I have forgotten) that caught fire, if a drush command tried to call APIs of the disabled module it lived with. Perhaps this was deemed to be common. Once we know what sort of seatbelts we want to apply, we should insure things still work the way we want them to with this patch. |
Drupal is very clear that disabled modules never even get their code loaded. I think our historical consistency with that is a good thing, and we should not load any commandfiles from such modules. Folks can include the commandfiles manually with --include |
To clarify, I'll test what happens with disabled modules commandfiles and report back. |
Oh, okay, I was confused about the location you were putting your commandfile. If your commandfile is in a global location, then this patch is fine -- it seems to me that there should be no affect on how Drush searches for commandfiles in modules with this change. Thank you for testing and confirming this, though. |
Ok,
|
Cool. This is definitely an improvement, then. |
Stop by bootstrap to DRUPAL_ROOT when searching for commandfiles
Wouldn't hurt to backport this to Drush 7, but not necessary either, I think. |
Drush is unable to detect drupal-version-specific commandfiles without a full bootstrap.
This is not neccesary for such commandfiles that only want to operate on
DRUPAL_ROOT
orDRUPAL_SITE
phases. Indeed it is very bad if the site is not installed yet.My case: I'm willing to provide
settingsphp.d8.drush.inc
andsettingsphp.d7.drush.inc
for https://www.drupal.org/project/settingsphp. Drush fails with "command not found" because I'm running on a site not installed yet so it can't bootstrap toDRUPAL_FULL
and the commandfiles are not reachable from the Drush preflight phase.