therealssj / tfa

TFA 8.x fork
0 stars 0 forks source link

Check for composer dependencies during module installation #7

Closed paraacha closed 8 years ago

paraacha commented 8 years ago

As specified in the composer.json file, the module depends on the PHP package christian-riesen/otp for its working. A user needs to install this package before installing the module.

So the logical thing is to stop the module from being installed if this dependency is not met. A simple hook_requirements() implementation will do the job.

paraacha commented 8 years ago

The following code, in tfa.install, would take care of the issue:

/**
 * Implements hook_requirements().
 */
function tfa_requirements($phase) {
  $requirements = array();

  $requirements['tfa'] = array(
    'title' => t('Two-factor Authentication (TFA)'),
  );

  if (class_exists('\Otp\Otp')) {
    $requirements['tfa']['severity'] = REQUIREMENT_OK;
  }
  else {
    $requirements['tfa']['severity'] = REQUIREMENT_ERROR;
    $requirements['tfa']['description'] = t("Please install the 'christian-riesen/otp' library via composer. See the module README for instructions.");
  }

  return $requirements;
}
therealssj commented 8 years ago

marked for next commit.