Closed (fixed)
Project:
Drush
Version:
8.x-6.x-dev
Component:
Base system (internal API)
Priority:
Normal
Category:
Feature request
Assigned:
Issue tags:
Reporter:
Created:
12 Jul 2013 at 21:17 UTC
Updated:
2 Apr 2014 at 15:55 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
greg.1.anderson commentedHere's a patch. The code was practically made to do this. It's much less confusing for folks if they can count on hooks firing uniformly. (Note: the two new calls to drush_log are nice for testing this, but perhaps should be removed before committing it to reduce noise in debug mode. Then again, most commands only implement one callback hook; maybe it's okay to keep these here.)
Comment #2
wonder95 commentedFirst of all, thanks for this patch and for whipping it up so quickly.
I tested it, and was able to use my post_COMMAND() hook with the callback still defined in the command.
Comment #3
moshe weitzman commentedLooks fine to me. Ideally we add a test but we can @todo that if needed.
Comment #4
greg.1.anderson commentedThis was really easy to test; all I needed to do was add a callback to the unit-invoke test. Without this patch, hooks are not supported, and the test fails.
Adding this test exposed another issue. Prior to this patch, the command hook was based on the callback name, not the command name, in instances where the callback hooks were supported. This isn't right in the general case, though, where the command hooks are supported regardless of the naming conventions used by the callback function. For example, in the case of unit-invoke, when I added a callback that changed the primary function to drush_unit_invoke_primary, that changed the command hook from unit_invoke to unit_invoke_primary. I therefore changed the code in command.inc to preserve the command hook, so that the addition of a callback function would not change the name of the command hook functions.
This is a change from Drush 5, and will affect any command that depends on this somewhat odd behavior. The only thing I found so far that does depend on this is the completion unit tests. The easy thing to do in instances like this is to set the command hook in the command record. The command hook is what is used to generate the function names used in the command hooks, so setting the command hook for all of the completion commands to the same value restored the previous behavior it depended on.
For details, see http://drupalcode.org/project/drush.git/commitdiff/f3963f0
Comment #5
moshe weitzman commentedI think this introduced a test failure in testCacheGetSetClear class. I am seeing two command callbacks are getting called instead of one. drush_cache_command_get (good) and drush_cache_get (bad). Let me know how you think this should be fixed.
Comment #6
greg.1.anderson commentedI made two adjustments to fix this. First, the 'normal' command hook is no longer called if a 'callback' command hook is supplied. This should be sufficient to fix the reported problem. Second, I added an 'invoke hooks' item that may be set FALSE to avoid all command hooks when a 'callback' is specified. This can be used if a function is still experiencing filename collisions with the command hooks.
Comment #7
moshe weitzman commentedCommitted, after adjusting commandCase test so it passes. Thanks Greg.
Note that I'm not sure we should have made another configuration element for the completion hooks. I'm thinking we should have renamed those functions and expected anyone else using the old behavior to do the same. Not a big deal though.
Comment #8
wonder95 commentedOne incredibly minor nit to pick on the last patch: in the doc block, the correct spelling is "suppress" (not "supress)".
Comment #9
greg.1.anderson commentedFixed typo. Thanks.
Comment #11
eastdrive commentedI'm trying to apply this patch but I can't find a version of Drush that it's compatible with - i.e. that contains an implementation of _drush_invoke_hooks().
Can anybody help me?
Many thanks.
Comment #12
helmo commented@eastdrive: This already got committed per #7 and is in the 6.0 version.
See http://drupalcode.org/project/drush.git/commitdiff/a0e602c1236e8aefe079a...
Comment #13
eastdrive commentedThanks very much @helmo. My hooks still aren't firing so it must be something we're doing wrong.
Your input was very much appreciated.