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