You are here

function better_statistics_uninstall in Better Statistics 7

Same name and namespace in other branches
  1. 8 better_statistics.install \better_statistics_uninstall()
  2. 6 better_statistics.install \better_statistics_uninstall()

Implements hook_uninstall().

Returns the accesslog schema to Core's declared default.

File

./better_statistics.install, line 56
Install and uninstall functions for the Better Statistics module.

Code

function better_statistics_uninstall() {

  // Get all fields that are live in the DB now.
  $live_fields = array_keys(db_select('accesslog', 'a')
    ->fields('a')
    ->range(0, 1)
    ->execute()
    ->fetchAssoc());

  // Get the declared default fields.
  $access_schema = drupal_get_schema_unprocessed('statistics', 'accesslog');
  $default_fields = $access_schema['fields'];

  // If the live field doesn't exist in the default fields, remove it.
  foreach ($live_fields as $field) {
    if (!isset($default_fields[$field])) {
      db_drop_field('accesslog', $field);
    }
  }

  // If an accesslog mode-type was declared, return it to a simple on/off state.
  $stats_enable_al = variable_get('statistics_enable_access_log', 0);
  if ($stats_enable_al > 1) {
    variable_set('statistics_enable_access_log', (int) (bool) $stats_enable_al);
  }

  // If a content hit counter mode was declared, return it to its on/off state.
  $stats_enable_ev = variable_get('statistics_count_content_views', 0);
  if ($stats_enable_ev > 1) {
    variable_set('statistics_count_content_views', (int) (bool) $stats_enable_ev);
  }
  variable_del('better_statistics_fields');
  variable_del('better_statistics_active_incs');
  variable_del('statistics_access_log_restrictions_cache');
  variable_del('statistics_access_log_restrictions_page');
  variable_del('statistics_access_log_restrictions_pages');
  variable_del('statistics_access_log_restrictions_roles');
  variable_del('statistics_access_log_restrictions_dnt');
  variable_del('statistics_log_to_db');
}