Skip to content
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

Fixed use of DRUPAL_ROOT in cache:rebuild command. #4713

Conversation

joachim-n
Copy link
Contributor

@joachim-n joachim-n commented Mar 27, 2021

Fixes #4712.

@weitzman
Copy link
Member

Thanks for the PR. If the constant is unreliable, that’s a core bug and I'd rather not work around it in Drush. We use DRUPAL_ROOT elsewhere as well.

@joachim-n
Copy link
Contributor Author

Well in the relevant core issue, https://www.drupal.org/project/drupal/issues/1792310, there is discussion about deprecating DRUPAL_ROOT. So I think removing it from Drush would be a good idea.

@weitzman
Copy link
Member

If that constant goes away, we'll use whatever its replacement is.

@weitzman weitzman closed this Mar 29, 2021
@shaal
Copy link

shaal commented Nov 8, 2021

@joachim-n Thank you for point me to this PR.
I'll utilize this trick in DrupalPod.

Without this, when using the special structure of /repos/drupal/core that is symlinked via composer into /web/core, it is impossible to run the most popular and important drush command of all time - drush cr.

Even if this does get fixed in Drupal core, older Drupal versions (8.9.x, 9.1.x, 9.2.x) won't be able to take advantage of this fix.

@joachim-n
Copy link
Contributor Author

@shaal I think I've fixed the problem this PR had with newer versions of Drush.
I've pushed it to the this MR's branch, but it's not showing up here. Can you figure it out?

@joachim-n
Copy link
Contributor Author

Ah nope, drush cr still kills off contrib modules.

@weitzman
Copy link
Member

Can you try out #5147 and see if it helps? You can prob just hack your Drush directly since only a few lines changed.

Ah nope, drush cr still kills off contrib modules.

That sounds like #3391 (which is thought to be a drupal core problem)

@shaal
Copy link

shaal commented May 15, 2022

@weitzman I tried applying patch #5147 it doesn't solve the problem; it has the same issue as in @joachim-n's patch.

I tested it locally (https://github.com/joachim-n/drupal-core-development-project + patch in this issue, as well as patch in #5147), and I tested it using DrupalPod.
The problem remains the same, on a special Drupal core setup, using repos/drupal and symlink core and vendor directories - running drush cr hides any contrib modules installed. Clearing cache in UI restore expected functionality.

Steps to replicate:

  1. Open Drupal core in DrupalPod
  2. Log in as admin (admin / admin)
  3. Go to /admin/modules
  4. Confirm admin_toolbar module is installed
  5. Go to /admin/config/development/performance
  6. Press the button Clear all caches
  7. Confirm admin_toolbar is still installed.
  8. In terminal, type ddev drush cr
  9. Notice that now admin_toolbar is no longer installed.
  10. Clear cache through the UI
  11. admin_toolbar is installed as expected.

@weitzman
Copy link
Member

Would be good if someone could see if #3391 is at fault. the symptom is the same.

@joachim-n
Copy link
Contributor Author

joachim-n commented May 19, 2022

I don't think this is easily fixable in Drush.

function drupal_rebuild($class_loader, Request $request) {

This doesn't allow us to pass in anything about the app root, and so it will go to DrupalKernel::guessApplicationRoot(), which just works with DIR and so will get it wrong.

The only thing to do would be for Drush to make a copy of drupal_rebuild() which passes in the correct app root when instantiating DrupalKernel. I doubt @weitzman would be happy with that!

Although -- can a package alter an existing command to switch its callback? We could make a package which replaces the cr command and has a drupal_rebuild() copy.

@weitzman
Copy link
Member

Thanks for the analysis.

You are right that I don't relish maintaining a copy of drupal_rebuild(). I will however pass $root to it (see #5149) , and then interested folks can petition Drupal core to add an optional param to it. I don't see why anyone would object to that. That patch could be safely backported to 9.x and 8.x.

can a package alter an existing command to switch its callback?

Yes, see https://github.com/consolidation/annotated-command#replace-command-hook. Perhaps https://github.com/consolidation/annotated-command#commandinfo-alterers would work as well.

@joachim-n
Copy link
Contributor Author

joachim-n commented May 19, 2022

I will however pass $root to it

I don't think that's needed -- when the core DRUPAL_ROOT issue is fixed, this all should Just Work (famous last words!!)

Though a fix to drupal_rebuild() might get in sooner, OTOH.

@weitzman
Copy link
Member

Though a fix to drupal_rebuild() might get in sooner, OTOH.

Right.

@shaal
Copy link

shaal commented May 19, 2022

@joachim with #5149, do you think it can fix the problem we're seeing (before drupal core fixes it)

@joachim-n
Copy link
Contributor Author

@shaal I've pushed a Drush command replacement to the composer project. Can you have a look?

@weitzman
Copy link
Member

Code looks good. If you verified that your code is getting called instead drush's, then its good. If you have trouble with that, see https://www.drush.org/latest/commands/#auto-discovered-commands

@joachim-n
Copy link
Contributor Author

Thanks for having a look @weitzman. I've tried it on my local install, after a drush cr I still have the admin toolbar working, which wasn't the case before. (Also, it crashed often enough while I was copy-pasting all the class imports I'd missed to know it's getting called! :p)

@shaal
Copy link

shaal commented May 19, 2022

@joachim-n I tested your latest update in DrupalPod joachim-n/drupal-core-development-project@e3f5c7f

It works! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

drush cr doesn't work if Drupal is symlinked in by Composer (Drush 12)
3 participants