tracker.install

Install, update, and uninstall functions for tracker.module.

File

drupal-7.x/modules/tracker/tracker.install
View source
  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. variable_del('tracker_index_nid');
  11. variable_del('tracker_batch_size');
  12. }
  13. /**
  14. * Implements hook_enable().
  15. */
  16. function tracker_enable() {
  17. $max_nid = db_query('SELECT MAX(nid) FROM {node}')->fetchField();
  18. if ($max_nid != 0) {
  19. variable_set('tracker_index_nid', $max_nid);
  20. // To avoid timing out while attempting to do a complete indexing, we
  21. // simply call our cron job to remove stale records and begin the process.
  22. tracker_cron();
  23. }
  24. }
  25. /**
  26. * Implements hook_schema().
  27. */
  28. function tracker_schema() {
  29. $schema['tracker_node'] = array(
  30. 'description' => 'Tracks when nodes were last changed or commented on.',
  31. 'fields' => array(
  32. 'nid' => array(
  33. 'description' => 'The {node}.nid this record tracks.',
  34. 'type' => 'int',
  35. 'unsigned' => TRUE,
  36. 'not null' => TRUE,
  37. 'default' => 0,
  38. ),
  39. 'published' => array(
  40. 'description' => 'Boolean indicating whether the node is published.',
  41. 'type' => 'int',
  42. 'not null' => FALSE,
  43. 'default' => 0,
  44. 'size' => 'tiny',
  45. ),
  46. 'changed' => array(
  47. 'description' => 'The Unix timestamp when the node was most recently saved or commented on.',
  48. 'type' => 'int',
  49. 'unsigned' => TRUE,
  50. 'not null' => TRUE,
  51. 'default' => 0,
  52. ),
  53. ),
  54. 'indexes' => array(
  55. 'tracker' => array('published', 'changed'),
  56. ),
  57. 'primary key' => array('nid'),
  58. 'foreign keys' => array(
  59. 'tracked_node' => array(
  60. 'table' => 'node',
  61. 'columns' => array('nid' => 'nid'),
  62. ),
  63. ),
  64. );
  65. $schema['tracker_user'] = array(
  66. 'description' => 'Tracks when nodes were last changed or commented on, for each user that authored the node or one of its comments.',
  67. 'fields' => array(
  68. 'nid' => array(
  69. 'description' => 'The {node}.nid this record tracks.',
  70. 'type' => 'int',
  71. 'unsigned' => TRUE,
  72. 'not null' => TRUE,
  73. 'default' => 0,
  74. ),
  75. 'uid' => array(
  76. 'description' => 'The {users}.uid of the node author or commenter.',
  77. 'type' => 'int',
  78. 'not null' => TRUE,
  79. 'default' => 0,
  80. ),
  81. 'published' => array(
  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' => array(
  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' => array(
  97. 'tracker' => array('uid', 'published', 'changed'),
  98. ),
  99. 'primary key' => array('nid', 'uid'),
  100. 'foreign keys' => array(
  101. 'tracked_node' => array(
  102. 'table' => 'node',
  103. 'columns' => array('nid' => 'nid'),
  104. ),
  105. 'tracked_user' => array(
  106. 'table' => 'users',
  107. 'columns' => array('uid' => 'uid'),
  108. ),
  109. ),
  110. );
  111. return $schema;
  112. }
  113. /**
  114. * @addtogroup updates-6.x-to-7.x
  115. * @{
  116. */
  117. /**
  118. * Create new tracker_node and tracker_user tables.
  119. */
  120. function tracker_update_7000() {
  121. $schema['tracker_node'] = array(
  122. 'description' => 'Tracks when nodes were last changed or commented on',
  123. 'fields' => array(
  124. 'nid' => array(
  125. 'description' => 'The {node}.nid this record tracks.',
  126. 'type' => 'int',
  127. 'unsigned' => TRUE,
  128. 'not null' => TRUE,
  129. 'default' => 0,
  130. ),
  131. 'published' => array(
  132. 'description' => 'Boolean indicating whether the node is published.',
  133. 'type' => 'int',
  134. 'not null' => FALSE,
  135. 'default' => 0,
  136. 'size' => 'tiny',
  137. ),
  138. 'changed' => array(
  139. 'description' => 'The Unix timestamp when the node was most recently saved or commented on.',
  140. 'type' => 'int',
  141. 'unsigned' => TRUE,
  142. 'not null' => TRUE,
  143. 'default' => 0,
  144. ),
  145. ),
  146. 'indexes' => array(
  147. 'tracker' => array('published', 'changed'),
  148. ),
  149. 'primary key' => array('nid'),
  150. 'foreign keys' => array(
  151. 'tracked_node' => array(
  152. 'table' => 'node',
  153. 'columns' => array('nid' => 'nid'),
  154. ),
  155. ),
  156. );
  157. $schema['tracker_user'] = array(
  158. 'description' => 'Tracks when nodes were last changed or commented on, for each user that authored the node or one of its comments.',
  159. 'fields' => array(
  160. 'nid' => array(
  161. 'description' => 'The {node}.nid this record tracks.',
  162. 'type' => 'int',
  163. 'unsigned' => TRUE,
  164. 'not null' => TRUE,
  165. 'default' => 0,
  166. ),
  167. 'uid' => array(
  168. 'description' => 'The {users}.uid of the node author or commenter.',
  169. 'type' => 'int',
  170. 'not null' => TRUE,
  171. 'default' => 0,
  172. ),
  173. 'published' => array(
  174. 'description' => 'Boolean indicating whether the node is published.',
  175. 'type' => 'int',
  176. 'not null' => FALSE,
  177. 'default' => 0,
  178. 'size' => 'tiny',
  179. ),
  180. 'changed' => array(
  181. 'description' => 'The Unix timestamp when the node was most recently saved or commented on.',
  182. 'type' => 'int',
  183. 'unsigned' => TRUE,
  184. 'not null' => TRUE,
  185. 'default' => 0,
  186. ),
  187. ),
  188. 'indexes' => array(
  189. 'tracker' => array('uid', 'published', 'changed'),
  190. ),
  191. 'primary key' => array('nid', 'uid'),
  192. 'foreign keys' => array(
  193. 'tracked_node' => array(
  194. 'table' => 'node',
  195. 'columns' => array('nid' => 'nid'),
  196. ),
  197. 'tracked_user' => array(
  198. 'table' => 'users',
  199. 'columns' => array('uid' => 'uid'),
  200. ),
  201. ),
  202. );
  203. foreach ($schema as $name => $table) {
  204. db_create_table($name, $table);
  205. }
  206. $max_nid = db_query('SELECT MAX(nid) FROM {node}')->fetchField();
  207. if ($max_nid != 0) {
  208. variable_set('tracker_index_nid', $max_nid);
  209. }
  210. }
  211. /**
  212. * @} End of "addtogroup updates-6.x-to-7.x".
  213. */