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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kasperg’s picture

And here's the patch.

kasperg’s picture

Oops. #1 had paths relative to the Drupal root. This one should apply.

agentrickard’s picture

Awesome. Check for typos in the comments though. I saw at least one.

kasperg’s picture

Here'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"

kasperg’s picture

Last minute consistency caused domain-cache-clear callback to override cache-clear resulting in cache clearing loops :).

Here's another patch.

agentrickard’s picture

I thought about this a little more. This is only useful if you are using different cache tables per domain, correct?

kasperg’s picture

Correct.

agentrickard’s picture

Status: Needs review » Needs work

Then it should be a drush command for domain_prefix.

kasperg’s picture

Noted.

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.

agentrickard’s picture

Abstracting that to drush domain-command FOO is very desirable. If it works reliably.

kasperg’s picture

It 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 or domain-prefix-command?
- Regarding module placement: domain or domain_prefix?

kasperg’s picture

Title: Clear cache across all domains using Drush » Execute a Drush command across all domains
Version: 6.x-2.12 » 6.x-2.x-dev
Status: Needs work » Needs review
FileSize
2.64 KB

Here's a new patch which implements drush domain-command. Better late than never.

It supports clearing cache through drush domain-command cc all.

agentrickard’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev

6.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.

helmo’s picture

Here'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?

interdruper’s picture

Status: Needs review » Reviewed & tested by the community

Patch #14 for 7.x-3.x works fine for me.

In some installations, the used drush_shell_exec_interactive() command may issue this error:

sh: /usr/share/pear/drush/drush.php: Permission denied



A workaround may consist in giving exec permission to that file:

sudo chmod +x /usr/share/pear/php/drush/drush.php
agentrickard’s picture

Status: Reviewed & tested by the community » Needs review

Is there any way to avoid that error other than file permissions?

gabrielu’s picture

For 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.

Andreas Radloff’s picture

I 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.

function drush_weekly_menu_send_all() {
  // As domain configuration can only be initialized during the Drush bootstrap
  // we need to assemble and execute a new Drush shell command on each domain.

  // Execute the command for each domain
  foreach (domain_domains() as $domain) {
    drush_print('[' . $domain['subdomain'] . '] Sending newsletters...');

    // Execute the command.
    drush_invoke_process('@self', 'weekly-menu-send', array(), array('uri' => $domain['scheme'] . '://' . $domain['subdomain']));
  }
}

Dion't forget the info hook:

/**
 * Implements hook_drush_command().
 */
function mymodule_drush_command() {
  $items = array();

  $items['weekly-menu-send-all'] = array(
    'description' => "Sends out the weekly menu for all domains.",
    'callback' => 'drush_weekly_menu_send_all',
    'drupal dependencies' => array('mymodule'),
  );

  return $items;
}