You are here

statistics.install in Zircon Profile 8

Same filename and directory in other branches
  1. 8.0 core/modules/statistics/statistics.install

Install and update functions for the Statistics module.

File

core/modules/statistics/statistics.install
View source
<?php

/**
 * @file
 * Install and update functions for the Statistics module.
 */

/**
 * Implements hook_uninstall().
 */
function statistics_uninstall() {

  // Remove states.
  \Drupal::state()
    ->delete('statistics.node_counter_scale');
  \Drupal::state()
    ->delete('statistics.day_timestamp');
}

/**
 * Implements hook_schema().
 */
function statistics_schema() {
  $schema['node_counter'] = array(
    'description' => 'Access statistics for {node}s.',
    'fields' => array(
      'nid' => array(
        'description' => 'The {node}.nid for these statistics.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'totalcount' => array(
        'description' => 'The total number of times the {node} has been viewed.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'big',
      ),
      'daycount' => array(
        'description' => 'The total number of times the {node} has been viewed today.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'medium',
      ),
      'timestamp' => array(
        'description' => 'The most recent time the {node} has been viewed.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'nid',
    ),
  );
  return $schema;
}

/**
 * Disable the Statistics module if the node module is not enabled.
 */
function statistics_update_8001() {
  if (!\Drupal::moduleHandler()
    ->moduleExists('node')) {
    if (\Drupal::service('module_installer')
      ->uninstall(array(
      'statistics',
    ), TRUE)) {
      return 'The statistics module depends on the node module and has therefore been uninstalled.';
    }
    else {
      return 'There was an error uninstalling the statistcs module.';
    }
  }
}

/**
 * Disable the Statistics module if the node module is not enabled.
 */
function statistics_update_8002() {

  // Set the new configuration setting for max age to the initial value.
  \Drupal::configFactory()
    ->getEditable('statistics.settings')
    ->set('display_max_age', 3600)
    ->save();
}

Functions

Namesort descending Description
statistics_schema Implements hook_schema().
statistics_uninstall Implements hook_uninstall().
statistics_update_8001 Disable the Statistics module if the node module is not enabled.
statistics_update_8002 Disable the Statistics module if the node module is not enabled.