tracker.install 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * @file
  4. * Install, update, and uninstall functions for tracker.module.
  5. */
  6. /**
  7. * Implements hook_uninstall().
  8. */
  9. function tracker_uninstall() {
  10. \Drupal::state()->delete('tracker.index_nid');
  11. }
  12. /**
  13. * Implements hook_install().
  14. */
  15. function tracker_install() {
  16. $max_nid = db_query('SELECT MAX(nid) FROM {node}')->fetchField();
  17. if ($max_nid != 0) {
  18. \Drupal::state()->set('tracker.index_nid', $max_nid);
  19. // To avoid timing out while attempting to do a complete indexing, we
  20. // simply call our cron job to remove stale records and begin the process.
  21. tracker_cron();
  22. }
  23. }
  24. /**
  25. * Implements hook_schema().
  26. */
  27. function tracker_schema() {
  28. $schema['tracker_node'] = [
  29. 'description' => 'Tracks when nodes were last changed or commented on.',
  30. 'fields' => [
  31. 'nid' => [
  32. 'description' => 'The {node}.nid this record tracks.',
  33. 'type' => 'int',
  34. 'unsigned' => TRUE,
  35. 'not null' => TRUE,
  36. 'default' => 0,
  37. ],
  38. 'published' => [
  39. 'description' => 'Boolean indicating whether the node is published.',
  40. 'type' => 'int',
  41. 'not null' => FALSE,
  42. 'default' => 0,
  43. 'size' => 'tiny',
  44. ],
  45. 'changed' => [
  46. 'description' => 'The Unix timestamp when the node was most recently saved or commented on.',
  47. 'type' => 'int',
  48. 'unsigned' => TRUE,
  49. 'not null' => TRUE,
  50. 'default' => 0,
  51. ],
  52. ],
  53. 'indexes' => [
  54. 'tracker' => ['published', 'changed'],
  55. ],
  56. 'primary key' => ['nid'],
  57. 'foreign keys' => [
  58. 'tracked_node' => [
  59. 'table' => 'node',
  60. 'columns' => ['nid' => 'nid'],
  61. ],
  62. ],
  63. ];
  64. $schema['tracker_user'] = [
  65. 'description' => 'Tracks when nodes were last changed or commented on, for each user that authored the node or one of its comments.',
  66. 'fields' => [
  67. 'nid' => [
  68. 'description' => 'The {node}.nid this record tracks.',
  69. 'type' => 'int',
  70. 'unsigned' => TRUE,
  71. 'not null' => TRUE,
  72. 'default' => 0,
  73. ],
  74. 'uid' => [
  75. 'description' => 'The {users}.uid of the node author or commenter.',
  76. 'type' => 'int',
  77. 'unsigned' => TRUE,
  78. 'not null' => TRUE,
  79. 'default' => 0,
  80. ],
  81. 'published' => [
  82. 'description' => 'Boolean indicating whether the node is published.',
  83. 'type' => 'int',
  84. 'not null' => FALSE,
  85. 'default' => 0,
  86. 'size' => 'tiny',
  87. ],
  88. 'changed' => [
  89. 'description' => 'The Unix timestamp when the node was most recently saved or commented on.',
  90. 'type' => 'int',
  91. 'unsigned' => TRUE,
  92. 'not null' => TRUE,
  93. 'default' => 0,
  94. ],
  95. ],
  96. 'indexes' => [
  97. 'tracker' => ['uid', 'published', 'changed'],
  98. ],
  99. 'primary key' => ['nid', 'uid'],
  100. 'foreign keys' => [
  101. 'tracked_node' => [
  102. 'table' => 'node',
  103. 'columns' => ['nid' => 'nid'],
  104. ],
  105. 'tracked_user' => [
  106. 'table' => 'users',
  107. 'columns' => ['uid' => 'uid'],
  108. ],
  109. ],
  110. ];
  111. return $schema;
  112. }