statistics.install 2.17 KB
Newer Older
1
2
<?php

3
4
/**
 * @file
5
 * Install and update functions for the Statistics module.
6
7
 */

8
9
10
11
12
/**
 * Implements hook_uninstall().
 */
function statistics_uninstall() {
  // Remove states.
13
14
  \Drupal::state()->delete('statistics.node_counter_scale');
  \Drupal::state()->delete('statistics.day_timestamp');
15
16
}

17
/**
18
 * Implements hook_schema().
19
20
 */
function statistics_schema() {
21
22
23
24
25
26
  $schema['node_counter'] = array(
    'description' => 'Access statistics for {node}s.',
    'fields' => array(
      'nid' => array(
        'description' => 'The {node}.nid for these statistics.',
        'type' => 'int',
27
        'unsigned' => TRUE,
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
        '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'),
  );

58
59
  return $schema;
}
60
61
62
63
64
65
66
67
68
69
70
71
72
73

/**
 * 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.';
    }
  }
}
74
75
76
77
78
79
80
81

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