annotate core/modules/statistics/statistics.install @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /**
Chris@0 4 * @file
Chris@0 5 * Install and update functions for the Statistics module.
Chris@0 6 */
Chris@0 7
Chris@0 8 /**
Chris@0 9 * Implements hook_uninstall().
Chris@0 10 */
Chris@0 11 function statistics_uninstall() {
Chris@0 12 // Remove states.
Chris@0 13 \Drupal::state()->delete('statistics.node_counter_scale');
Chris@0 14 \Drupal::state()->delete('statistics.day_timestamp');
Chris@0 15 }
Chris@0 16
Chris@0 17 /**
Chris@0 18 * Implements hook_schema().
Chris@0 19 */
Chris@0 20 function statistics_schema() {
Chris@0 21 $schema['node_counter'] = [
Chris@0 22 'description' => 'Access statistics for {node}s.',
Chris@0 23 'fields' => [
Chris@0 24 'nid' => [
Chris@0 25 'description' => 'The {node}.nid for these statistics.',
Chris@0 26 'type' => 'int',
Chris@0 27 'unsigned' => TRUE,
Chris@0 28 'not null' => TRUE,
Chris@0 29 'default' => 0,
Chris@0 30 ],
Chris@0 31 'totalcount' => [
Chris@0 32 'description' => 'The total number of times the {node} has been viewed.',
Chris@0 33 'type' => 'int',
Chris@0 34 'unsigned' => TRUE,
Chris@0 35 'not null' => TRUE,
Chris@0 36 'default' => 0,
Chris@0 37 'size' => 'big',
Chris@0 38 ],
Chris@0 39 'daycount' => [
Chris@0 40 'description' => 'The total number of times the {node} has been viewed today.',
Chris@0 41 'type' => 'int',
Chris@0 42 'unsigned' => TRUE,
Chris@0 43 'not null' => TRUE,
Chris@0 44 'default' => 0,
Chris@0 45 'size' => 'medium',
Chris@0 46 ],
Chris@0 47 'timestamp' => [
Chris@0 48 'description' => 'The most recent time the {node} has been viewed.',
Chris@0 49 'type' => 'int',
Chris@0 50 'unsigned' => TRUE,
Chris@0 51 'not null' => TRUE,
Chris@0 52 'default' => 0,
Chris@0 53 ],
Chris@0 54 ],
Chris@0 55 'primary key' => ['nid'],
Chris@0 56 ];
Chris@0 57
Chris@0 58 return $schema;
Chris@0 59 }
Chris@0 60
Chris@0 61 /**
Chris@0 62 * Disable the Statistics module if the node module is not enabled.
Chris@0 63 */
Chris@0 64 function statistics_update_8001() {
Chris@0 65 if (!\Drupal::moduleHandler()->moduleExists('node')) {
Chris@0 66 if (\Drupal::service('module_installer')->uninstall(['statistics'], TRUE)) {
Chris@0 67 return 'The statistics module depends on the node module and has therefore been uninstalled.';
Chris@0 68 }
Chris@0 69 else {
Chris@0 70 return 'There was an error uninstalling the statistcs module.';
Chris@0 71 }
Chris@0 72 }
Chris@0 73 }
Chris@0 74
Chris@0 75 /**
Chris@0 76 * Disable the Statistics module if the node module is not enabled.
Chris@0 77 */
Chris@0 78 function statistics_update_8002() {
Chris@0 79 // Set the new configuration setting for max age to the initial value.
Chris@0 80 \Drupal::configFactory()->getEditable('statistics.settings')->set('display_max_age', 3600)->save();
Chris@0 81 }
Chris@0 82
Chris@0 83 /**
Chris@0 84 * Remove access_log settings.
Chris@0 85 */
Chris@0 86 function statistics_update_8300() {
Chris@0 87 \Drupal::configFactory()->getEditable('statistics.settings')->clear('access_log')->save();
Chris@0 88 }