You are here

function raven_requirements in Raven: Sentry Integration 7.4

Same name and namespace in other branches
  1. 8.2 raven.install \raven_requirements()
  2. 8 raven.install \raven_requirements()
  3. 7 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 78
Install, update, and uninstall functions for the Raven module.

Code

function raven_requirements($phase) {
  $t = get_t();
  $requirements = [];
  switch ($phase) {
    case 'runtime':
      if (class_exists(SentrySdk::class)) {
        $requirements['raven_version'] = [
          'title' => $t('Sentry PHP SDK'),
          'value' => Event::createEvent()
            ->getSdkVersion(),
          'severity' => REQUIREMENT_OK,
        ];
        if (!variable_get('raven_enabled', FALSE)) {
          $requirements['raven_enabled'] = [
            'title' => $t('Sentry logging'),
            'value' => $t('Disabled'),
            'description' => $t('Sentry logging is disabled.'),
            'severity' => REQUIREMENT_OK,
          ];
        }
        elseif (empty($_SERVER['SENTRY_DSN']) && !variable_get('raven_dsn', '')) {
          $requirements['raven_dsn'] = [
            'title' => $t('Sentry logging'),
            'value' => $t('Disabled'),
            'description' => $t('Sentry logging is enabled but Sentry DSN is not set.'),
            'severity' => REQUIREMENT_WARNING,
          ];
        }
        else {
          $requirements['raven_dsn'] = [
            'title' => $t('Sentry logging'),
            'value' => $t('Enabled'),
            'description' => $t('Sentry is set to log to %dsn.', [
              '%dsn' => empty($_SERVER['SENTRY_DSN']) ? variable_get('raven_dsn', '') : $_SERVER['SENTRY_DSN'],
            ]),
            'severity' => REQUIREMENT_OK,
          ];
          if (variable_get('raven_trace', FALSE)) {
            $requirements['raven_trace'] = [
              'title' => $t('Sentry reflection tracing'),
              'value' => $t('Enabled'),
              'description' => $t('Sentry reflection tracing is enabled, which results in sensitive data being logged by Sentry.'),
              'severity' => REQUIREMENT_WARNING,
            ];
          }
          else {
            $requirements['raven_trace'] = [
              'title' => $t('Sentry reflection tracing'),
              'value' => $t('Disabled'),
              'description' => $t('Sentry reflection tracing is disabled.'),
              'severity' => REQUIREMENT_OK,
            ];
          }
        }
        if ($client = raven_get_client()) {
          if ($environment = $client
            ->getOptions()
            ->getEnvironment()) {
            $requirements['raven_environment'] = [
              'title' => $t('Sentry environment'),
              'value' => check_plain($environment),
              'severity' => REQUIREMENT_OK,
            ];
          }
          if ($release = $client
            ->getOptions()
            ->getRelease()) {
            $requirements['raven_release'] = [
              'title' => $t('Sentry release'),
              'value' => check_plain($release),
              'severity' => REQUIREMENT_OK,
            ];
          }
        }
      }
      else {
        $requirements['raven_library'] = [
          'title' => $t('Sentry PHP SDK'),
          'value' => $t('Not loaded'),
          'description' => $t('The Sentry PHP SDK could not be loaded. Please install it via <code>composer require sentry/sdk:^3</code> and ensure composer dependencies are being autoloaded. For instructions see the Raven module README.md file.'),
          'severity' => REQUIREMENT_ERROR,
        ];
      }
      break;
    default:
      break;
  }
  return $requirements;
}