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