statistics.install 2.3 KB

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