You are here

raven.install in Raven: Sentry Integration 7.4

Install, update, and uninstall functions for the Raven module.

File

raven.install
View source
<?php

/**
 * @file
 * Install, update, and uninstall functions for the Raven module.
 */
use Sentry\Event;
use Sentry\SentrySdk;

/**
 * Implements hook_install().
 */
function raven_uninstall() {
  variable_del('raven_enabled');
  variable_del('raven_dsn');
  variable_del('raven_timeout');
  variable_del('raven_message_limit');
  variable_del('raven_exception_handler');
  variable_del('raven_fatal_error_handler');
  variable_del('raven_error_handler');
  variable_del('raven_error_levels');
  variable_del('raven_stack');
  variable_del('raven_trace');
  variable_del('raven_trace_user');
  variable_del('raven_watchdog_handler');
  variable_del('raven_watchdog_levels');
  variable_del('raven_watchdog_page_not_found');
  variable_del('raven_ssl');
  variable_del('raven_ca_cert');
  variable_del('raven_js_enabled');
  variable_del('raven_public_dsn');
  variable_del('raven_js_source');
  variable_del('raven_js_cdn_url');
  variable_del('raven_environment');
  variable_del('raven_release');
  variable_del('raven_ignored_types');
  variable_del('raven_set_report_uri');
  variable_del('raven_rate_limit');
  variable_del('raven_send_user_data');
  variable_del('raven_send_request_body');
  variable_del('raven_js_traces_sample_rate');
  variable_del('raven_auto_session_tracking');
  variable_del('raven_send_client_reports');
}

/**
 * Migrate raven_watchdog_page_not_found to raven_ignored_types.
 */
function raven_update_7201() {
  if (!variable_get('raven_watchdog_page_not_found', FALSE)) {
    variable_set('raven_ignored_types', 'page not found');
  }
  variable_del('raven_watchdog_page_not_found');
}

/**
 * Remove obsolete variables.
 */
function raven_update_7202() {
  variable_del('raven_error_handler');
  variable_del('raven_error_levels');
  variable_del('raven_exception_handler');
  variable_del('raven_watchdog_handler');
}

/**
 * Remove obsolete variables.
 */
function raven_update_7301() {
  variable_del('raven_js_source');
  variable_del('raven_js_cdn_url');
}

/**
 * Implements hook_requirements().
 */
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;
}

Functions

Namesort descending Description
raven_requirements Implements hook_requirements().
raven_uninstall Implements hook_install().
raven_update_7201 Migrate raven_watchdog_page_not_found to raven_ignored_types.
raven_update_7202 Remove obsolete variables.
raven_update_7301 Remove obsolete variables.