statistics.install

Same filename and directory in other branches
  1. 7.x modules/statistics/statistics.install
  2. 9 core/modules/statistics/statistics.install
  3. 8.9.x core/modules/statistics/statistics.install
  4. 11.x 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.
 */

// cspell:ignore daycount totalcount

/**
 * 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'] = [
    'description' => 'Access statistics for {node}s.',
    'fields' => [
      'nid' => [
        'description' => 'The {node}.nid for these statistics.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
      'totalcount' => [
        'description' => 'The total number of times the {node} has been viewed.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'big',
      ],
      'daycount' => [
        'description' => 'The total number of times the {node} has been viewed today.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'medium',
      ],
      'timestamp' => [
        'description' => 'The most recent time the {node} has been viewed.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'big',
      ],
    ],
    'primary key' => [
      'nid',
    ],
  ];
  return $schema;
}

/**
 * Implements hook_update_last_removed().
 */
function statistics_update_last_removed() {
  return 8300;
}

/**
 * Remove the year 2038 date limitation.
 */
function statistics_update_10100(&$sandbox = NULL) {
  $connection = \Drupal::database();
  if ($connection->schema()
    ->tableExists('node_counter') && $connection->databaseType() != 'sqlite') {
    $new = [
      'description' => 'The most recent time the {node} has been viewed.',
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
      'size' => 'big',
    ];
    $connection->schema()
      ->changeField('node_counter', 'timestamp', 'timestamp', $new);
  }
}

Functions

Title Deprecated Summary
statistics_schema Implements hook_schema().
statistics_uninstall Implements hook_uninstall().
statistics_update_10100 Remove the year 2038 date limitation.
statistics_update_last_removed Implements hook_update_last_removed().

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.