You are here

raven.install in Raven: Sentry Integration 7

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_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');
}

/**
 * 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 = 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;
}

/**
 * Implements hook_update_N().
 */
function raven_update_7000(&$sandbox) {
  if (!module_enable(array(
    'xautoload',
  ))) {
    throw new DrupalUpdateException(t('Please install xautoload module and run this update again.'));
  }
  return t('Please read the Raven module README.md for information about new library dependencies.');
}

Functions