node.install 12.5 KB
Newer Older
1
2
3
<?php
// $Id$

4
5
6
7
8
/**
 * @file
 * Install, update and uninstall functions for the node module.
 */

9
/**
10
 * Implement hook_schema().
11
12
13
 */
function node_schema() {
  $schema['node'] = array(
14
    'description' => 'The base table for nodes.',
15
    'fields' => array(
16
      'nid' => array(
17
        'description' => 'The primary identifier for a node.',
18
19
        'type' => 'serial',
        'unsigned' => TRUE,
20
21
        'not null' => TRUE,
      ),
22
      'vid' => array(
23
        'description' => 'The current {node_revision}.vid version identifier.',
24
25
26
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
27
28
        'default' => 0,
      ),
29
      'type' => array(
30
        'description' => 'The {node_type}.type of this node.',
31
32
33
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
34
35
        'default' => '',
      ),
36
      'language' => array(
37
        'description' => 'The {languages}.language of this node.',
38
39
40
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
41
42
        'default' => '',
      ),
43
      'title' => array(
44
        'description' => 'The title of this node, always treated as non-markup plain text.',
45
46
47
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
48
49
        'default' => '',
      ),
50
      'uid' => array(
51
        'description' => 'The {users}.uid that owns this node; initially, this is the user that created it.',
52
53
        'type' => 'int',
        'not null' => TRUE,
54
55
        'default' => 0,
      ),
56
      'status' => array(
57
        'description' => 'Boolean indicating whether the node is published (visible to non-administrators).',
58
59
        'type' => 'int',
        'not null' => TRUE,
60
61
        'default' => 1,
      ),
62
      'created' => array(
63
        'description' => 'The Unix timestamp when the node was created.',
64
65
        'type' => 'int',
        'not null' => TRUE,
66
67
        'default' => 0,
      ),
68
      'changed' => array(
69
        'description' => 'The Unix timestamp when the node was most recently saved.',
70
71
        'type' => 'int',
        'not null' => TRUE,
72
73
        'default' => 0,
      ),
74
      'comment' => array(
75
        'description' => 'Whether comments are allowed on this node: 0 = no, 1 = closed (read only), 2 = open (read/write).',
76
77
        'type' => 'int',
        'not null' => TRUE,
78
79
        'default' => 0,
      ),
80
      'promote' => array(
81
        'description' => 'Boolean indicating whether the node should be displayed on the front page.',
82
83
        'type' => 'int',
        'not null' => TRUE,
84
85
        'default' => 0,
      ),
86
      'moderate' => array(
87
        'description' => 'Previously, a boolean indicating whether the node was "in moderation"; mostly no longer used.',
88
89
        'type' => 'int',
        'not null' => TRUE,
90
91
        'default' => 0,
      ),
92
      'sticky' => array(
93
        'description' => 'Boolean indicating whether the node should be displayed at the top of lists in which it appears.',
94
95
        'type' => 'int',
        'not null' => TRUE,
96
97
        'default' => 0,
      ),
98
      'tnid' => array(
99
        'description' => 'The translation set id for this node, which equals the node id of the source post in each set.',
100
101
102
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
103
104
        'default' => 0,
      ),
105
      'translate' => array(
106
        'description' => 'A boolean indicating whether this translation page needs to be updated.',
107
108
        'type' => 'int',
        'not null' => TRUE,
109
        'default' => 0,
110
      ),
111
    ),
112
113
114
115
    'indexes' => array(
      'node_changed'        => array('changed'),
      'node_created'        => array('created'),
      'node_moderate'       => array('moderate'),
116
      'node_frontpage'      => array('promote', 'status', 'sticky', 'created'),
117
118
119
120
121
122
      'node_status_type'    => array('status', 'type', 'nid'),
      'node_title_type'     => array('title', array('type', 4)),
      'node_type'           => array(array('type', 4)),
      'uid'                 => array('uid'),
      'tnid'                => array('tnid'),
      'translate'           => array('translate'),
123
    ),
124
    'unique keys' => array(
125
126
      'vid' => array('vid'),
    ),
127
    'primary key' => array('nid'),
128
  );
129
130

  $schema['node_access'] = array(
131
    'description' => 'Identifies which realm/grant pairs a user must possess in order to view, update, or delete specific nodes.',
132
    'fields' => array(
133
      'nid' => array(
134
        'description' => 'The {node}.nid this record affects.',
135
136
137
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
138
139
        'default' => 0,
      ),
140
      'gid' => array(
141
        'description' => "The grant ID a user must possess in the specified realm to gain this row's privileges on the node.",
142
143
144
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
145
146
        'default' => 0,
      ),
147
      'realm' => array(
148
        'description' => 'The realm in which the user must possess the grant ID. Each node access node can define one or more realms.',
149
150
151
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
152
153
        'default' => '',
      ),
154
      'grant_view' => array(
155
        'description' => 'Boolean indicating whether a user with the realm/grant pair can view this node.',
156
157
158
159
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
160
161
        'size' => 'tiny',
      ),
162
      'grant_update' => array(
163
        'description' => 'Boolean indicating whether a user with the realm/grant pair can edit this node.',
164
165
166
167
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
168
169
        'size' => 'tiny',
      ),
170
      'grant_delete' => array(
171
        'description' => 'Boolean indicating whether a user with the realm/grant pair can delete this node.',
172
173
174
175
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
176
        'size' => 'tiny',
177
      ),
178
    ),
179
    'primary key' => array('nid', 'gid', 'realm'),
180
  );
181

182
  $schema['node_revision'] = array(
183
    'description' => 'Stores information about each saved version of a {node}.',
184
    'fields' => array(
185
      'nid' => array(
186
        'description' => 'The {node} this version belongs to.',
187
188
189
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
190
191
        'default' => 0,
      ),
192
      'vid' => array(
193
        'description' => 'The primary identifier for this version.',
194
195
        'type' => 'serial',
        'unsigned' => TRUE,
196
197
        'not null' => TRUE,
      ),
198
      'uid' => array(
199
        'description' => 'The {users}.uid that created this version.',
200
201
        'type' => 'int',
        'not null' => TRUE,
202
203
        'default' => 0,
      ),
204
      'title' => array(
205
        'description' => 'The title of this version.',
206
207
208
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
209
210
        'default' => '',
      ),
211
      'body' => array(
212
        'description' => 'The body of this version.',
213
214
        'type' => 'text',
        'not null' => TRUE,
215
216
        'size' => 'big',
      ),
217
      'teaser' => array(
218
        'description' => 'The teaser of this version.',
219
220
        'type' => 'text',
        'not null' => TRUE,
221
222
        'size' => 'big',
      ),
223
      'log' => array(
224
        'description' => 'The log entry explaining the changes in this version.',
225
226
        'type' => 'text',
        'not null' => TRUE,
227
228
        'size' => 'big',
      ),
229
      'timestamp' => array(
230
        'description' => 'A Unix timestamp indicating when this version was created.',
231
232
        'type' => 'int',
        'not null' => TRUE,
233
234
        'default' => 0,
      ),
235
      'format' => array(
236
        'description' => "The text format used by this version's body.",
237
238
        'type' => 'int',
        'not null' => TRUE,
239
        'default' => 0,
240
      ),
241
    ),
242
243
    'indexes' => array(
      'nid' => array('nid'),
244
245
      'uid' => array('uid'),
    ),
246
    'primary key' => array('vid'),
247
  );
248
249

  $schema['node_type'] = array(
250
    'description' => 'Stores information about all defined {node} types.',
251
    'fields' => array(
252
      'type' => array(
253
        'description' => 'The machine-readable name of this type.',
254
255
        'type' => 'varchar',
        'length' => 32,
256
257
        'not null' => TRUE,
      ),
258
      'name' => array(
259
        'description' => 'The human-readable name of this type.',
260
261
262
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
263
264
        'default' => '',
      ),
265
      'base' => array(
266
        'description' => 'The base string used to construct callbacks corresponding to this node type.',
267
268
        'type' => 'varchar',
        'length' => 255,
269
270
271
        'not null' => TRUE,
      ),
      'description' => array(
272
        'description' => 'A brief description of this type.',
273
274
        'type' => 'text',
        'not null' => TRUE,
275
276
        'size' => 'medium',
      ),
277
      'help' => array(
278
        'description' => 'Help information shown to the user when creating a {node} of this type.',
279
280
        'type' => 'text',
        'not null' => TRUE,
281
282
        'size' => 'medium',
      ),
283
      'has_title' => array(
284
        'description' => 'Boolean indicating whether this type uses the {node}.title field.',
285
286
287
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
288
289
        'size' => 'tiny',
      ),
290
      'title_label' => array(
291
        'description' => 'The label displayed for the title field on the edit form.',
292
293
294
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
295
296
        'default' => '',
      ),
297
      'has_body' => array(
298
        'description' => 'Boolean indicating whether this type uses the {node_revision}.body field.',
299
300
301
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
302
303
        'size' => 'tiny',
      ),
304
      'body_label' => array(
305
        'description' => 'The label displayed for the body field on the edit form.',
306
307
308
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
309
310
        'default' => '',
      ),
311
      'min_word_count' => array(
312
        'description' => 'The minimum number of words the body must contain.',
313
314
315
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
316
317
        'size' => 'small',
      ),
318
      'custom' => array(
319
        'description' => 'A boolean indicating whether this type is defined by a module (FALSE) or by a user via a module like the Content Construction Kit (TRUE).',
320
321
322
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
323
324
        'size' => 'tiny',
      ),
325
      'modified' => array(
326
        'description' => 'A boolean indicating whether this type has been modified by an administrator; currently not used in any way.',
327
328
329
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
330
331
        'size' => 'tiny',
      ),
332
      'locked' => array(
333
        'description' => 'A boolean indicating whether the administrator can change the machine name of this type.',
334
335
336
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
337
338
        'size' => 'tiny',
      ),
339
      'orig_type' => array(
340
        'description' => 'The original machine-readable name of this node type. This may be different from the current type name if the locked field is 0.',
341
342
343
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
344
        'default' => '',
345
      ),
346
    ),
347
    'primary key' => array('type'),
348
  );
349
350
351

  return $schema;
}
352
353

/**
354
355
 * @defgroup updates-6.x-to-7.x System updates from 6.x to 7.x
 * @{
356
357
358
359
360
361
362
363
364
365
366
367
368
369
 */

/**
 * Fix node type 'module' attribute to avoid name-space conflicts.
 */
function node_update_7000() {
  $ret = array();

  $ret[] = update_sql("UPDATE {node_type} SET module = 'node_content' WHERE module = 'node'");
  db_change_field($ret, 'node_type', 'module', 'base', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE));

  return $ret;
}

370
371
372
373
374
375
376
377
378
/**
 * Rename {node_revisions} table to {node_revision}.
 */
function node_update_7001() {
  $ret = array();
  db_rename_table($ret, 'node_revisions', 'node_revision');
  return $ret;
}

379
380
381
382
383
384
385
386
387
388
/**
 * Extend the node_promote_status index to include all fields required for the node page query.
 */
function node_update_7002() {
  $ret = array();
  db_drop_index($ret, 'node', 'node_promote_status');
  db_add_index($ret, 'node', 'node_frontpage', array('promote', 'status', 'sticky', 'created'));
  return $ret;
}

389
/**
390
391
392
393
 * Remove the node_counter if the statistics module is uninstalled.
 */
function node_update_7003() {
  $ret = array();
394
  if (drupal_get_installed_schema_version('statistics') == SCHEMA_UNINSTALLED) {
395
396
397
398
399
400
401
402
    db_drop_table($ret, 'node_counter');
  }
  return $ret;
}

/**
 * @} End of "defgroup updates-6.x-to-7.x"
 * The next series of updates should start at 8000.
403
 */