I was developing a module which I didn't want it to be enabled if certain conditions are met and I was using hook_requirements for that purpose.
Using drush, I noticed that although the error message from the hook_requirement was thrown, the module was still installed/enabled, which I think is wrong.
Debugging through drush I found out that one bit of the install process is a bit different from the actual site, and in particular, the lack of use of the drupal_check_module() function in the proper part of the logic.
Currently, the only place where the hook_requirements is invoked is when the system_modules form is executed, and that happens after the module is installed/enabled.
Attached is a fix that properly uses drupal_check_module() early in the enable logic, and skip the module from the process if there's an error in it.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | 593314_drush_enable_hook_requirement_error.patch | 1.77 KB | hanoii |
| drush_enable_hook_requirement_error.patch | 1.22 KB | hanoii |
Comments
Comment #1
hanoiiReviewing my patch, I noticed that I was affecting a variable which was also later used in the same function.
Attached is a fix with a slightly different approach which doesn't alter that variable.
Comment #2
hanoiiComment #3
moshe weitzman commentedCan we please log a notice when modules are skipped?
Comment #4
hanoiiI don't mind adding a log to the patch, but there's going to be a log already below in the function. Because the module that was skipped is part of the $modules array (the ones that were requested to be enabled), the following snippet (part of the current code) will found that one of the requested modules' status is still 0 (disabled) and then log the proper error about the module cannot being enabled.
Comment #5
hanoiiAnd worth noting that the failed requirement it's likely to set a proper error message as well.
Comment #6
bas.hr commentedIf you need already existing module to test with, here is one fresh to reproduce the bug: http://drupal.org/project/epsacrop
Comment #7
moshe weitzman commentedComment #8
hanoiiBumping up this issue, any work or review needed from me?
Comment #9
hanoiiBumping this issue up once more. If these bumps up bother please let me know and I stop. I just go over my issues from time to time and bump up the ones that I feel worth some attention.
Comment #10
moshe weitzman commentedCommitted. Thanks.
Would be great if you could take a look at #617428: Cancelling drush disable causes dependent modules to be disabled
Comment #11
hanoiidone :)!