Projet

Général

Profil

Paste
Télécharger (6,02 ko) Statistiques
| Branche: | Révision:

root / drupal7 / modules / tracker / tracker.install @ c7768a53

1
<?php
2

    
3
/**
4
 * @file
5
 * Install, update, and uninstall functions for tracker.module.
6
 */
7

    
8
/**
9
 * Implements hook_uninstall().
10
 */
11
function tracker_uninstall() {
12
  variable_del('tracker_index_nid');
13
  variable_del('tracker_batch_size');
14
}
15

    
16
/**
17
 * Implements hook_enable().
18
 */
19
function tracker_enable() {
20
  $max_nid = db_query('SELECT MAX(nid) FROM {node}')->fetchField();
21
  if ($max_nid != 0) {
22
    variable_set('tracker_index_nid', $max_nid);
23
    // To avoid timing out while attempting to do a complete indexing, we
24
    // simply call our cron job to remove stale records and begin the process.
25
    tracker_cron();
26
  }
27
}
28

    
29
/**
30
 * Implements hook_schema().
31
 */
32
function tracker_schema() {
33
  $schema['tracker_node'] = array(
34
    'description' => 'Tracks when nodes were last changed or commented on.',
35
    'fields' => array(
36
      'nid' => array(
37
        'description' => 'The {node}.nid this record tracks.',
38
        'type' => 'int',
39
        'unsigned' => TRUE,
40
        'not null' => TRUE,
41
        'default' => 0,
42
      ),
43
      'published' => array(
44
        'description' => 'Boolean indicating whether the node is published.',
45
        'type' => 'int',
46
        'not null' => FALSE,
47
        'default' => 0,
48
        'size' => 'tiny',
49
      ),
50
      'changed' => array(
51
        'description' => 'The Unix timestamp when the node was most recently saved or commented on.',
52
        'type' => 'int',
53
        'unsigned' => TRUE,
54
        'not null' => TRUE,
55
        'default' => 0,
56
      ),
57
    ),
58
    'indexes' => array(
59
      'tracker' => array('published', 'changed'),
60
    ),
61
    'primary key' => array('nid'),
62
    'foreign keys' => array(
63
      'tracked_node' => array(
64
        'table' => 'node',
65
        'columns' => array('nid' => 'nid'),
66
      ),
67
    ),
68
  );
69

    
70
  $schema['tracker_user'] = array(
71
    'description' => 'Tracks when nodes were last changed or commented on, for each user that authored the node or one of its comments.',
72
    'fields' => array(
73
      'nid' => array(
74
        'description' => 'The {node}.nid this record tracks.',
75
        'type' => 'int',
76
        'unsigned' => TRUE,
77
        'not null' => TRUE,
78
        'default' => 0,
79
      ),
80
      'uid' => array(
81
        'description' => 'The {users}.uid of the node author or commenter.',
82
        'type' => 'int',
83
        'not null' => TRUE,
84
        'default' => 0,
85
      ),
86
      'published' => array(
87
        'description' => 'Boolean indicating whether the node is published.',
88
        'type' => 'int',
89
        'not null' => FALSE,
90
        'default' => 0,
91
        'size' => 'tiny',
92
      ),
93
      'changed' => array(
94
        'description' => 'The Unix timestamp when the node was most recently saved or commented on.',
95
        'type' => 'int',
96
        'unsigned' => TRUE,
97
        'not null' => TRUE,
98
        'default' => 0,
99
      ),
100
    ),
101
    'indexes' => array(
102
      'tracker' => array('uid', 'published', 'changed'),
103
    ),
104
    'primary key' => array('nid', 'uid'),
105
    'foreign keys' => array(
106
      'tracked_node' => array(
107
        'table' => 'node',
108
        'columns' => array('nid' => 'nid'),
109
      ),
110
      'tracked_user' => array(
111
        'table' => 'users',
112
        'columns' => array('uid' => 'uid'),
113
      ),
114
    ),
115
  );
116

    
117
  return $schema;
118
}
119

    
120
/**
121
 * @addtogroup updates-6.x-to-7.x
122
 * @{
123
 */
124

    
125
/**
126
 * Create new tracker_node and tracker_user tables.
127
 */
128
function tracker_update_7000() {
129
  $schema['tracker_node'] = array(
130
    'description' => 'Tracks when nodes were last changed or commented on',
131
    'fields' => array(
132
      'nid' => array(
133
        'description' => 'The {node}.nid this record tracks.',
134
        'type' => 'int',
135
        'unsigned' => TRUE,
136
        'not null' => TRUE,
137
        'default' => 0,
138
      ),
139
      'published' => array(
140
        'description' => 'Boolean indicating whether the node is published.',
141
        'type' => 'int',
142
        'not null' => FALSE,
143
        'default' => 0,
144
        'size' => 'tiny',
145
      ),
146
      'changed' => array(
147
        'description' => 'The Unix timestamp when the node was most recently saved or commented on.',
148
        'type' => 'int',
149
        'unsigned' => TRUE,
150
        'not null' => TRUE,
151
        'default' => 0,
152
      ),
153
    ),
154
    'indexes' => array(
155
      'tracker' => array('published', 'changed'),
156
    ),
157
    'primary key' => array('nid'),
158
    'foreign keys' => array(
159
      'tracked_node' => array(
160
        'table' => 'node',
161
        'columns' => array('nid' => 'nid'),
162
      ),
163
    ),
164
  );
165

    
166
  $schema['tracker_user'] = array(
167
    'description' => 'Tracks when nodes were last changed or commented on, for each user that authored the node or one of its comments.',
168
    'fields' => array(
169
      'nid' => array(
170
        'description' => 'The {node}.nid this record tracks.',
171
        'type' => 'int',
172
        'unsigned' => TRUE,
173
        'not null' => TRUE,
174
        'default' => 0,
175
      ),
176
      'uid' => array(
177
        'description' => 'The {users}.uid of the node author or commenter.',
178
        'type' => 'int',
179
        'not null' => TRUE,
180
        'default' => 0,
181
      ),
182
      'published' => array(
183
        'description' => 'Boolean indicating whether the node is published.',
184
        'type' => 'int',
185
        'not null' => FALSE,
186
        'default' => 0,
187
        'size' => 'tiny',
188
      ),
189
      'changed' => array(
190
        'description' => 'The Unix timestamp when the node was most recently saved or commented on.',
191
        'type' => 'int',
192
        'unsigned' => TRUE,
193
        'not null' => TRUE,
194
        'default' => 0,
195
      ),
196
    ),
197
    'indexes' => array(
198
      'tracker' => array('uid', 'published', 'changed'),
199
    ),
200
    'primary key' => array('nid', 'uid'),
201
    'foreign keys' => array(
202
      'tracked_node' => array(
203
        'table' => 'node',
204
        'columns' => array('nid' => 'nid'),
205
      ),
206
      'tracked_user' => array(
207
        'table' => 'users',
208
        'columns' => array('uid' => 'uid'),
209
      ),
210
    ),
211
  );
212

    
213
  foreach ($schema as $name => $table) {
214
    db_create_table($name, $table);
215
  }
216

    
217
  $max_nid = db_query('SELECT MAX(nid) FROM {node}')->fetchField();
218
  if ($max_nid != 0) {
219
    variable_set('tracker_index_nid', $max_nid);
220
  }
221
}
222

    
223
/**
224
 * @} End of "addtogroup updates-6.x-to-7.x".
225
 */