statistics.install

Install and update functions for the Statistics module.

File

drupal/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.
  state()
    ->delete('statistics.node_counter_scale');
  state()
    ->delete('statistics.day_timestamp');
}

/**
 * Implements hook_schema().
 */
function statistics_schema() {
  $schema['accesslog'] = array(
    'description' => 'Stores site access information for statistics.',
    'fields' => array(
      'aid' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key: Unique accesslog ID.',
      ),
      'sid' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Browser session ID of user that visited page.',
      ),
      'title' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
        'description' => 'Title of page visited.',
      ),
      'path' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
        'description' => 'Internal path to page visited (relative to Drupal root.)',
      ),
      'url' => array(
        'type' => 'text',
        'not null' => FALSE,
        'description' => 'Referrer URI.',
      ),
      'hostname' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => FALSE,
        'description' => 'Hostname of user that visited the page.',
      ),
      'uid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => FALSE,
        'default' => 0,
        'description' => 'User {users}.uid that visited the page.',
      ),
      'timer' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Time in milliseconds that the page took to load.',
      ),
      'timestamp' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Timestamp of when the page was visited.',
      ),
    ),
    'indexes' => array(
      'accesslog_timestamp' => array(
        'timestamp',
      ),
      'uid' => array(
        'uid',
      ),
    ),
    'primary key' => array(
      'aid',
    ),
    'foreign keys' => array(
      'visitor' => array(
        'table' => 'users',
        'columns' => array(
          'uid' => 'uid',
        ),
      ),
    ),
  );
  $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;
}

/**
 * Moves statistics settings from variables to config.
 *
 * @ingroup config_upgrade
 */
function statistics_update_8000() {
  update_variables_to_config('statistics.settings', array(
    'statistics_count_content_views' => 'count_content_views',
    'statistics_enable_access_log' => 'access_log.enabled',
    'statistics_flush_accesslog_timer' => 'access_log.max_lifetime',
    'statistics_block_top_day_num' => 'block.popular.top_day_limit',
    'statistics_block_top_all_num' => 'block.popular.top_all_limit',
    'statistics_block_top_last_num' => 'block.popular.top_recent_limit',
  ));
}

/**
 * Make *id fields unsigned.
 */
function statistics_update_8001() {
  db_drop_primary_key('node_counter');
  db_change_field('node_counter', 'nid', 'nid', array(
    'description' => 'The {node}.nid for these statistics.',
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ), array(
    'primary key' => array(
      'nid',
    ),
  ));
}

/**
 * Convert variables to state.
 */
function statistics_update_8002() {
  update_variables_to_state(array(
    'node_cron_views_scale' => 'statistics.node_counter_scale',
    'statistics_day_timestamp' => 'statistics.day_timestamp',
  ));
}

Functions

Namesort descending Description
statistics_schema Implements hook_schema().
statistics_uninstall Implements hook_uninstall().
statistics_update_8000 Moves statistics settings from variables to config.
statistics_update_8001 Make *id fields unsigned.
statistics_update_8002 Convert variables to state.