Drush's hook mechanisms are brilliant, and we use them extensively in Aegir. One limitation I've run into, though, is that there doesn't appear to be a convenient way to have two implementations targeting the same hook. That is, if I want to implement a drush_hook_post_COMMAND() hook that will run prior to another pre-existing implementation of drush_hook_post_COMMAND(), there's not really a good way to do so currently (at least, not to my knowledge).

Comments

moshe weitzman’s picture

One quick solution would be for us to add an alter hook in our invoke_all function.

ergonlogic’s picture

Status: Active » Needs review
StatusFileSize
new821 bytes

See the attached patch for a basic implementation. Is this what you had in mind? It allows things like:

function example_drush_invoke_alter($modules, $hook) {
  if ($hook == 'other_hook') {
    $module = array_pop($modules);
    array_unshift($modules, $module);
  }
}

I haven't tested it in my use-case yet, but I think it should work.

moshe weitzman’s picture

Yes that what I had in mind. Thanks.

ergonlogic’s picture

StatusFileSize
new1.85 KB

Same patch with docs. I'm not sure if/how we can write an automated test for a hook like this. Any suggestions?

moshe weitzman’s picture

Does this line need a '@' before $modules? - +function hook_drush_invoke_alter($modules, $hook) {. Seems like the example implementation needs a reference to $modules

ergonlogic’s picture

'@' would suppress errors, no? I don't understand why we'd need that. If you meant '&', then I think we could add one for clarity. But I believe the way drush_invoke_all_ref() works actually makes it unnecessary. It certainly works without it.

moshe weitzman’s picture

Status: Needs review » Fixed

Yes, I meant &. Sorry about that. We can omit it. Committed.

Status: Fixed » Closed (fixed)

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