Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Sometimes it would be nice to clear the cache on across all domains.
The following patch adds a domain-clear-cache (dcc) drush command which does that.
Comment | File | Size | Author |
---|---|---|---|
#17 | execute_a_drush_command-1336468-17.patch | 2.24 KB | gabrielu |
#14 | execute_a_drush_command-1336468-14.patch | 2.16 KB | helmo |
Comments
Comment #1
kasperg CreditAttribution: kasperg commentedAnd here's the patch.
Comment #2
kasperg CreditAttribution: kasperg commentedOops. #1 had paths relative to the Drupal root. This one should apply.
Comment #3
agentrickardAwesome. Check for typos in the comments though. I saw at least one.
Comment #4
kasperg CreditAttribution: kasperg commentedHere's a updated patch.
Changes:
- Typos should be fixed
- Renamed command to domain-cache-clear for consistecy
- Switched to interactive shell to let the user respond to prompts (e.g. missing type)
- Escaped arguments passed from domain-cache-clear to cache-clear to support "theme registry"
Comment #5
kasperg CreditAttribution: kasperg commentedLast minute consistency caused domain-cache-clear callback to override cache-clear resulting in cache clearing loops :).
Here's another patch.
Comment #6
agentrickardI thought about this a little more. This is only useful if you are using different cache tables per domain, correct?
Comment #7
kasperg CreditAttribution: kasperg commentedCorrect.
Comment #8
agentrickardThen it should be a drush command for domain_prefix.
Comment #9
kasperg CreditAttribution: kasperg commentedNoted.
As domain_prefix is not limited to cache tables I thought it might be useful to support executing any drush command across all domains á la
drush domain-prefix-command cc all
The change to the current patch enabling this should be straightforward.
Comment #10
agentrickardAbstracting that to
drush domain-command FOO
is very desirable. If it works reliably.Comment #11
kasperg CreditAttribution: kasperg commentedIt should work just as well as clear cache. All options passed to the overall command are passed along to the individual domains and prompts etc. for the individual domains are handled through interactive mode.
For clarification what would you prefer:
- Regarding drush command:
domain-command
ordomain-prefix-command
?- Regarding module placement: domain or domain_prefix?
Comment #12
kasperg CreditAttribution: kasperg commentedHere's a new patch which implements
drush domain-command
. Better late than never.It supports clearing cache through
drush domain-command cc all
.Comment #13
agentrickard6.x is closed to new features. This has to go in 7.x.3.
I suppose the only real use-case for this is alternate caching (such as Views provides) and table prefixing. In general I don't see much utility here.
Comment #14
helmo CreditAttribution: helmo commentedHere's a re-roll of #12 for 7.x-3.x with a few comment style improvements.
@agentrickard: Or is there an easier way to clear the cache tables of all domains?
Comment #15
interdruper CreditAttribution: interdruper commentedPatch #14 for 7.x-3.x works fine for me.
In some installations, the used drush_shell_exec_interactive() command may issue this error:
A workaround may consist in giving exec permission to that file:
Comment #16
agentrickardIs there any way to avoid that error other than file permissions?
Comment #17
gabrielu CreditAttribution: gabrielu at AG Prime commentedFor me is fine to give Execute rights for Drush.
I just have one small improvement to add, only run it for Active domains. Please see the attached.
Comment #18
Andreas Radloff CreditAttribution: Andreas Radloff commentedI had this problem in a shared environment. To avoid the permissions error caused by drush_shell_exec_interactive() you can write a custom Drush command in a modulename.drush.inc and use drush_invoke_process instead.
Dion't forget the info hook: