You are here

raven.install in Raven: Sentry Integration 7.3

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.
 */

/**
 * 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_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 = 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 = array();
      if (class_exists('Raven_Client')) {
        $raven['loaded'] = TRUE;
        $raven['version'] = Raven_Client::VERSION;
      }
      elseif (module_exists('libraries')) {
        $raven = libraries_load('sentry-php');
      }
      if ($raven && $raven['loaded']) {
        if (version_compare($raven['version'], 2, '<')) {
          $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" rel="noreferrer" target="_blank">@url</a>.', array(
              '@url' => $url,
            )),
            'severity' => REQUIREMENT_OK,
          );
        }
        else {
          $requirements['raven_version'] = array(
            'title' => $t('Sentry PHP library'),
            'value' => $raven['version'],
            'description' => $t('Please install version 1.x of the <a href="@url" rel="noreferrer" target="_blank">Sentry PHP library</a>.', array(
              '@url' => $url,
            )),
            'severity' => REQUIREMENT_ERROR,
          );
        }
        if (!variable_get('raven_enabled', FALSE)) {
          $requirements['raven_enabled'] = array(
            'title' => $t('Sentry logging'),
            'value' => $t('Disabled'),
            'description' => $t('Sentry logging is disabled.'),
            'severity' => REQUIREMENT_WARNING,
          );
        }
        elseif (empty($_SERVER['SENTRY_DSN']) && !variable_get('raven_dsn', '')) {
          $requirements['raven_dsn'] = array(
            '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'] = array(
            'title' => $t('Sentry logging'),
            'value' => $t('Enabled'),
            'description' => $t('Sentry is set to log to %dsn.', array(
              '%dsn' => empty($_SERVER['SENTRY_DSN']) ? variable_get('raven_dsn', '') : $_SERVER['SENTRY_DSN'],
            )),
            'severity' => REQUIREMENT_OK,
          );
          if (variable_get('raven_trace', FALSE)) {
            $requirements['raven_trace'] = array(
              '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'] = array(
              'title' => $t('Sentry reflection tracing'),
              'value' => $t('Disabled'),
              'description' => $t('Sentry reflection tracing is disabled.'),
              'severity' => REQUIREMENT_OK,
            );
          }
        }
        if ($client = raven_get_client()) {
          if ($client->environment) {
            $requirements['raven_environment'] = array(
              'title' => $t('Sentry environment'),
              'value' => check_plain($client->environment),
              'severity' => REQUIREMENT_OK,
            );
          }
          if ($client->release) {
            $requirements['raven_release'] = array(
              'title' => $t('Sentry release'),
              'value' => check_plain($client->release),
              '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 version 1.x of the <a href="@url" rel="noreferrer" target="_blank">Sentry PHP library</a> either via composer (into your vendor directory), or using libraries and xautoload modules (as <em>sites/all/libraries/sentry-php</em>). For instructions see the Raven module README.md file.', array(
            '@url' => $url,
          )),
          '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.