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.

Comments

hanoii’s picture

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

hanoii’s picture

Status: Active » Needs review
moshe weitzman’s picture

Status: Needs review » Needs work

Can we please log a notice when modules are skipped?

hanoii’s picture

Status: Needs work » Needs review

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

    foreach ($modules as $module_name) {
      if ($enable) { 
        if ($module_info[$module_name]->status) {
          drush_log(dt('!module was enabled successfully.', array('!module' => $module_info[$module_name]->info['name'])), 'ok');
        }
        else {
          drush_set_error('DRUSH_PM_ENABLE_MODULE_ISSUE', dt('> There was a problem enabling !module.', array('!module' => $module_name)));
        }
      }
      else { 
        if (!$module_info[$module_name]->status) {
          drush_log(dt('!module was disabled successfully.', array('!module' => $module_info[$module_name]->info['name'])), 'ok');
        }
        else {
          drush_set_error('DRUSH_PM_DISABLE_MODULE_ISSUE', dt('> There was a problem disabling !module.', array('!module' => $module_name)));
        }
      }
    }
hanoii’s picture

And worth noting that the failed requirement it's likely to set a proper error message as well.

bas.hr’s picture

If you need already existing module to test with, here is one fresh to reproduce the bug: http://drupal.org/project/epsacrop

moshe weitzman’s picture

Assigned: Unassigned » owen barton
Priority: Critical » Normal
hanoii’s picture

Bumping up this issue, any work or review needed from me?

hanoii’s picture

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

moshe weitzman’s picture

Status: Needs review » Fixed

Committed. Thanks.

Would be great if you could take a look at #617428: Cancelling drush disable causes dependent modules to be disabled

hanoii’s picture

done :)!

Status: Fixed » Closed (fixed)

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