You are here

function raven_requirements in Raven: Sentry Integration 7

Same name and namespace in other branches
  1. 8.2 raven.install \raven_requirements()
  2. 8 raven.install \raven_requirements()
  3. 7.4 raven.install \raven_requirements()
  4. 7.2 raven.install \raven_requirements()
  5. 7.3 raven.install \raven_requirements()
  6. 3.x raven.install \raven_requirements()

Implements hook_requirements().

File

./raven.install, line 35
Install, update, and uninstall functions for the Raven module.

Code

function raven_requirements($phase) {
  $t = get_t();
  $requirements = array();
  $url = 'https://github.com/getsentry/sentry-php/releases';
  $has_curl = function_exists('curl_init');
  $requirements['raven_curl'] = array(
    'title' => $t('cURL'),
    'value' => $has_curl ? $t('Enabled') : $t('Not found'),
  );
  if (!$has_curl) {
    $requirements['raven_curl']['severity'] = REQUIREMENT_ERROR;
    $requirements['raven_curl']['description'] = $t('Raven module could not be installed because the PHP <a href="@curl_url">cURL</a> extension is not available.', array(
      '@curl_url' => 'http://php.net/manual/en/curl.setup.php',
    ));
  }
  switch ($phase) {
    case 'runtime':
      $raven = libraries_load('sentry-php');
      if ($raven && $raven['loaded']) {
        $requirements['raven_version'] = array(
          'title' => $t('Sentry PHP library'),
          'value' => $raven['version'],
          'description' => $t('To check for newer versions of Sentry PHP, go to <a href="@url" target="_blank">@url</a>.', array(
            '@url' => $url,
          )),
          'severity' => REQUIREMENT_OK,
        );
        if (!variable_get('raven_enabled', FALSE)) {
          $requirements['raven_enabled'] = array(
            'title' => $t('Raven logging'),
            'value' => $t('Disabled'),
            'description' => $t('Raven logging is disabled.'),
            'severity' => REQUIREMENT_WARNING,
          );
        }
        elseif (!variable_get('raven_dsn', '')) {
          $requirements['raven_dsn'] = array(
            'title' => $t('Raven logging'),
            'value' => $t('Disabled'),
            'description' => $t('Raven logging is enabled but Sentry DSN is not set.'),
            'severity' => REQUIREMENT_WARNING,
          );
        }
        else {
          $requirements['raven_dsn'] = array(
            'title' => $t('Raven logging'),
            'value' => $t('Enabled'),
            'description' => $t('Raven is set to log to %dsn.', array(
              '%dsn' => variable_get('raven_dsn', ''),
            )),
            'severity' => REQUIREMENT_OK,
          );
          if (variable_get('raven_trace', FALSE)) {
            $requirements['raven_trace'] = array(
              'title' => $t('Raven reflection tracing'),
              'value' => $t('Enabled'),
              'description' => $t('Raven reflection tracing is enabled, which results in sensitive data being logged by Sentry.'),
              'severity' => REQUIREMENT_WARNING,
            );
          }
          else {
            $requirements['raven_trace'] = array(
              'title' => $t('Raven reflection tracing'),
              'value' => $t('Disabled'),
              'description' => $t('Raven reflection tracing is disabled.'),
              'severity' => REQUIREMENT_OK,
            );
          }
        }
      }
      else {
        $requirements['sentry_library'] = array(
          'title' => $t('Sentry PHP library'),
          'value' => $t('Not installed'),
          'description' => $t('The Sentry PHP library could not be loaded. Please install <a href="@url" target="_blank">Sentry PHP library</a> and its dependencies (Monolog and PSR Log).', array(
            '@url' => $url,
          )),
          'severity' => REQUIREMENT_ERROR,
        );
      }
      break;
    default:
      break;
  }
  return $requirements;
}