You are here

function mailhandler_requirements in Mailhandler 6.2

Same name and namespace in other branches
  1. 5 mailhandler.install \mailhandler_requirements()
  2. 6 mailhandler.install \mailhandler_requirements()
  3. 7.2 mailhandler.install \mailhandler_requirements()
  4. 7 mailhandler.install \mailhandler_requirements()

Implements hook_requirements().

Check the autoload is enabled.

File

./mailhandler.install, line 516
Install, update and uninstall functions for the Mailhandler module.

Code

function mailhandler_requirements($phase) {
  $requirements = array();

  // Ensure translations don't break at install time
  $t = get_t();
  $has_iconv = function_exists('iconv_mime_decode');
  $requirements['mailhandler_iconv'] = array(
    'title' => $t('Mailhandler iconv'),
    'description' => $t("Mailhandler requires that PHP's !ext is enabled in order to function properly.", array(
      '!ext' => l('iconv extension', 'http://www.php.net/manual/en/book.iconv.php'),
    )),
    'value' => $has_iconv ? $t('Enabled') : $t('Not found'),
    'severity' => $has_iconv ? REQUIREMENT_OK : REQUIREMENT_ERROR,
  );
  switch ($phase) {
    case 'runtime':
      $dependencies = array(
        'autoload' => '6.x-2.x',
      );
      $error = FALSE;
      $warning = FALSE;
      foreach ($dependencies as $module => $version_required) {
        if (!module_exists($module)) {
          $error = TRUE;
        }
        $path = drupal_get_path('module', $module);
        $info = drupal_parse_info_file($path . '/' . $module . '.info');
        $version_actual = $info['version'];
        if (drupal_substr($version_required, 0, 5) != drupal_substr($version_actual, 0, 5)) {
          $warning = TRUE;
        }
      }
      if ($error == TRUE) {
        $requirements['mailhandler_dependencies'] = array(
          'title' => $t('Mailhandler dependencies'),
          'description' => $t("Autoload is not installed."),
          'value' => $t('Not found'),
          'severity' => REQUIREMENT_ERROR,
        );
      }
      elseif ($warning == TRUE) {
        $requirements['mailhandler_dependencies'] = array(
          'title' => $t('Mailhandler dependencies'),
          'description' => $t("Mailhandler is not compatible with your version of Autoload."),
          'value' => $t('Not found or incorrect versions'),
          'severity' => REQUIREMENT_WARNING,
        );
      }
      $plugins = mailhandler_get_plugins('mailhandler', 'retrieve');
      if (count($plugins) == 1) {
        $requirements['mailhandler_retrieve'] = array(
          'title' => $t('Mailhandler retrieval plugins'),
          'description' => $t('No retrieval plugins are available. Please enable the Mailhandler PHP IMAP module, or another module providing a retrieval plugin.'),
          'value' => $t('Not found'),
          'severity' => REQUIREMENT_ERROR,
        );
      }
  }
  return $requirements;
}