Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pm:enable installs a module even if hook_requirements returns 'severity' => REQUIREMENT_ERROR #6006

Closed
wombatbuddy opened this issue May 14, 2024 · 5 comments

Comments

@wombatbuddy
Copy link

If we run the following command: drush en -y my_module and the hook_requirements returns 'severity' => REQUIREMENT_ERROR then Drush display the error message but still enables the module.

System Configuration

Q A
Drush version? 12.5.2.0
Drupal version? 10.2.4
PHP version 8.2.11
OS? Linux

Additional information
The similar 4874 issue is marked as closed here: #4874

@simesy
Copy link

simesy commented May 14, 2024

Just as a workaround, if this is a custom module you can add an exception for Drush. In the example below it prevents installing a module anywhere except locally on DDEV.

/**
 * Implements hook_requirements().
 */
function MY_MODULE_requirements(string $phase): array {
  $requirements = [];
  if ($phase == 'install') {
    $error = t('EXPLAIN WHY THE MODULE SHOULD NOT BE INSTALLED');

    if (getenv('IS_DDEV_PROJECT') != 'true' && php_sapi_name() == 'cli') {
        // Prevent user from bypassing with Drush.
        throw new \Exception($error);
      }

      // Normal Drupal install in the UI.
      $requirements['cc_test_no_production'] = [
        'severity' => REQUIREMENT_ERROR,
        'description' => $error,
      ];
    }
  }

  return $requirements;
}

@wombatbuddy
Copy link
Author

Thanks Simon!
Another workaround is in addition to implementing of the hook_requirements(), also uninstall a module in the hook_install().

@weitzman
Copy link
Member

weitzman commented May 15, 2024

The requirement check only stops for interactive requests. Passing -y makes it non-interactive. This could be changed now that we have a new major version (13).

@weitzman
Copy link
Member

I'm going to call this 'By Design'. The behavior you seek happens when you pass --no-interaction instead of of --yes. --yes is like passing --no-interaction with the addition of auto-replying 'yes'. to each confirmation prompt. Thats usually the equivalent to --no-interaction but some prompts, like this one, default to no and thus passing --yes overrides the default.

@weitzman weitzman closed this as not planned Won't fix, can't repro, duplicate, stale May 27, 2024
@simesy
Copy link

simesy commented May 28, 2024

with the addition of auto-replying 'yes'.

I don't really understand this. Via the UI it's not possible to install it under any circumstance when hook_requirements returns REQUIREMENT_ERROR. It's got nothing to do with the arguments passed in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants