comparison modules/node/node.install @ 0:ff03f76ab3fe

initial version
author danieleb <danielebarchiesi@me.com>
date Wed, 21 Aug 2013 18:51:11 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:ff03f76ab3fe
1 <?php
2
3 /**
4 * @file
5 * Install, update and uninstall functions for the node module.
6 */
7
8 /**
9 * Implements hook_schema().
10 */
11 function node_schema() {
12 $schema['node'] = array(
13 'description' => 'The base table for nodes.',
14 'fields' => array(
15 'nid' => array(
16 'description' => 'The primary identifier for a node.',
17 'type' => 'serial',
18 'unsigned' => TRUE,
19 'not null' => TRUE,
20 ),
21 // Defaults to NULL in order to avoid a brief period of potential
22 // deadlocks on the index.
23 'vid' => array(
24 'description' => 'The current {node_revision}.vid version identifier.',
25 'type' => 'int',
26 'unsigned' => TRUE,
27 'not null' => FALSE,
28 'default' => NULL,
29 ),
30 'type' => array(
31 'description' => 'The {node_type}.type of this node.',
32 'type' => 'varchar',
33 'length' => 32,
34 'not null' => TRUE,
35 'default' => '',
36 ),
37 'language' => array(
38 'description' => 'The {languages}.language of this node.',
39 'type' => 'varchar',
40 'length' => 12,
41 'not null' => TRUE,
42 'default' => '',
43 ),
44 'title' => array(
45 'description' => 'The title of this node, always treated as non-markup plain text.',
46 'type' => 'varchar',
47 'length' => 255,
48 'not null' => TRUE,
49 'default' => '',
50 ),
51 'uid' => array(
52 'description' => 'The {users}.uid that owns this node; initially, this is the user that created it.',
53 'type' => 'int',
54 'not null' => TRUE,
55 'default' => 0,
56 ),
57 'status' => array(
58 'description' => 'Boolean indicating whether the node is published (visible to non-administrators).',
59 'type' => 'int',
60 'not null' => TRUE,
61 'default' => 1,
62 ),
63 'created' => array(
64 'description' => 'The Unix timestamp when the node was created.',
65 'type' => 'int',
66 'not null' => TRUE,
67 'default' => 0,
68 ),
69 'changed' => array(
70 'description' => 'The Unix timestamp when the node was most recently saved.',
71 'type' => 'int',
72 'not null' => TRUE,
73 'default' => 0,
74 ),
75 'comment' => array(
76 'description' => 'Whether comments are allowed on this node: 0 = no, 1 = closed (read only), 2 = open (read/write).',
77 'type' => 'int',
78 'not null' => TRUE,
79 'default' => 0,
80 ),
81 'promote' => array(
82 'description' => 'Boolean indicating whether the node should be displayed on the front page.',
83 'type' => 'int',
84 'not null' => TRUE,
85 'default' => 0,
86 ),
87 'sticky' => array(
88 'description' => 'Boolean indicating whether the node should be displayed at the top of lists in which it appears.',
89 'type' => 'int',
90 'not null' => TRUE,
91 'default' => 0,
92 ),
93 'tnid' => array(
94 'description' => 'The translation set id for this node, which equals the node id of the source post in each set.',
95 'type' => 'int',
96 'unsigned' => TRUE,
97 'not null' => TRUE,
98 'default' => 0,
99 ),
100 'translate' => array(
101 'description' => 'A boolean indicating whether this translation page needs to be updated.',
102 'type' => 'int',
103 'not null' => TRUE,
104 'default' => 0,
105 ),
106 ),
107 'indexes' => array(
108 'node_changed' => array('changed'),
109 'node_created' => array('created'),
110 'node_frontpage' => array('promote', 'status', 'sticky', 'created'),
111 'node_status_type' => array('status', 'type', 'nid'),
112 'node_title_type' => array('title', array('type', 4)),
113 'node_type' => array(array('type', 4)),
114 'uid' => array('uid'),
115 'tnid' => array('tnid'),
116 'translate' => array('translate'),
117 ),
118 'unique keys' => array(
119 'vid' => array('vid'),
120 ),
121 'foreign keys' => array(
122 'node_revision' => array(
123 'table' => 'node_revision',
124 'columns' => array('vid' => 'vid'),
125 ),
126 'node_author' => array(
127 'table' => 'users',
128 'columns' => array('uid' => 'uid'),
129 ),
130 ),
131 'primary key' => array('nid'),
132 );
133
134 $schema['node_access'] = array(
135 'description' => 'Identifies which realm/grant pairs a user must possess in order to view, update, or delete specific nodes.',
136 'fields' => array(
137 'nid' => array(
138 'description' => 'The {node}.nid this record affects.',
139 'type' => 'int',
140 'unsigned' => TRUE,
141 'not null' => TRUE,
142 'default' => 0,
143 ),
144 'gid' => array(
145 'description' => "The grant ID a user must possess in the specified realm to gain this row's privileges on the node.",
146 'type' => 'int',
147 'unsigned' => TRUE,
148 'not null' => TRUE,
149 'default' => 0,
150 ),
151 'realm' => array(
152 'description' => 'The realm in which the user must possess the grant ID. Each node access node can define one or more realms.',
153 'type' => 'varchar',
154 'length' => 255,
155 'not null' => TRUE,
156 'default' => '',
157 ),
158 'grant_view' => array(
159 'description' => 'Boolean indicating whether a user with the realm/grant pair can view this node.',
160 'type' => 'int',
161 'unsigned' => TRUE,
162 'not null' => TRUE,
163 'default' => 0,
164 'size' => 'tiny',
165 ),
166 'grant_update' => array(
167 'description' => 'Boolean indicating whether a user with the realm/grant pair can edit this node.',
168 'type' => 'int',
169 'unsigned' => TRUE,
170 'not null' => TRUE,
171 'default' => 0,
172 'size' => 'tiny',
173 ),
174 'grant_delete' => array(
175 'description' => 'Boolean indicating whether a user with the realm/grant pair can delete this node.',
176 'type' => 'int',
177 'unsigned' => TRUE,
178 'not null' => TRUE,
179 'default' => 0,
180 'size' => 'tiny',
181 ),
182 ),
183 'primary key' => array('nid', 'gid', 'realm'),
184 'foreign keys' => array(
185 'affected_node' => array(
186 'table' => 'node',
187 'columns' => array('nid' => 'nid'),
188 ),
189 ),
190 );
191
192 $schema['node_revision'] = array(
193 'description' => 'Stores information about each saved version of a {node}.',
194 'fields' => array(
195 'nid' => array(
196 'description' => 'The {node} this version belongs to.',
197 'type' => 'int',
198 'unsigned' => TRUE,
199 'not null' => TRUE,
200 'default' => 0,
201 ),
202 'vid' => array(
203 'description' => 'The primary identifier for this version.',
204 'type' => 'serial',
205 'unsigned' => TRUE,
206 'not null' => TRUE,
207 ),
208 'uid' => array(
209 'description' => 'The {users}.uid that created this version.',
210 'type' => 'int',
211 'not null' => TRUE,
212 'default' => 0,
213 ),
214 'title' => array(
215 'description' => 'The title of this version.',
216 'type' => 'varchar',
217 'length' => 255,
218 'not null' => TRUE,
219 'default' => '',
220 ),
221 'log' => array(
222 'description' => 'The log entry explaining the changes in this version.',
223 'type' => 'text',
224 'not null' => TRUE,
225 'size' => 'big',
226 ),
227 'timestamp' => array(
228 'description' => 'A Unix timestamp indicating when this version was created.',
229 'type' => 'int',
230 'not null' => TRUE,
231 'default' => 0,
232 ),
233 'status' => array(
234 'description' => 'Boolean indicating whether the node (at the time of this revision) is published (visible to non-administrators).',
235 'type' => 'int',
236 'not null' => TRUE,
237 'default' => 1,
238 ),
239 'comment' => array(
240 'description' => 'Whether comments are allowed on this node (at the time of this revision): 0 = no, 1 = closed (read only), 2 = open (read/write).',
241 'type' => 'int',
242 'not null' => TRUE,
243 'default' => 0,
244 ),
245 'promote' => array(
246 'description' => 'Boolean indicating whether the node (at the time of this revision) should be displayed on the front page.',
247 'type' => 'int',
248 'not null' => TRUE,
249 'default' => 0,
250 ),
251 'sticky' => array(
252 'description' => 'Boolean indicating whether the node (at the time of this revision) should be displayed at the top of lists in which it appears.',
253 'type' => 'int',
254 'not null' => TRUE,
255 'default' => 0,
256 ),
257 ),
258 'indexes' => array(
259 'nid' => array('nid'),
260 'uid' => array('uid'),
261 ),
262 'primary key' => array('vid'),
263 'foreign keys' => array(
264 'versioned_node' => array(
265 'table' => 'node',
266 'columns' => array('nid' => 'nid'),
267 ),
268 'version_author' => array(
269 'table' => 'users',
270 'columns' => array('uid' => 'uid'),
271 ),
272 ),
273 );
274
275 $schema['node_type'] = array(
276 'description' => 'Stores information about all defined {node} types.',
277 'fields' => array(
278 'type' => array(
279 'description' => 'The machine-readable name of this type.',
280 'type' => 'varchar',
281 'length' => 32,
282 'not null' => TRUE,
283 ),
284 'name' => array(
285 'description' => 'The human-readable name of this type.',
286 'type' => 'varchar',
287 'length' => 255,
288 'not null' => TRUE,
289 'default' => '',
290 'translatable' => TRUE,
291 ),
292 'base' => array(
293 'description' => 'The base string used to construct callbacks corresponding to this node type.',
294 'type' => 'varchar',
295 'length' => 255,
296 'not null' => TRUE,
297 ),
298 'module' => array(
299 'description' => 'The module defining this node type.',
300 'type' => 'varchar',
301 'length' => 255,
302 'not null' => TRUE,
303 ),
304 'description' => array(
305 'description' => 'A brief description of this type.',
306 'type' => 'text',
307 'not null' => TRUE,
308 'size' => 'medium',
309 'translatable' => TRUE,
310 ),
311 'help' => array(
312 'description' => 'Help information shown to the user when creating a {node} of this type.',
313 'type' => 'text',
314 'not null' => TRUE,
315 'size' => 'medium',
316 'translatable' => TRUE,
317 ),
318 'has_title' => array(
319 'description' => 'Boolean indicating whether this type uses the {node}.title field.',
320 'type' => 'int',
321 'unsigned' => TRUE,
322 'not null' => TRUE,
323 'size' => 'tiny',
324 ),
325 'title_label' => array(
326 'description' => 'The label displayed for the title field on the edit form.',
327 'type' => 'varchar',
328 'length' => 255,
329 'not null' => TRUE,
330 'default' => '',
331 'translatable' => TRUE,
332 ),
333 'custom' => array(
334 'description' => 'A boolean indicating whether this type is defined by a module (FALSE) or by a user via Add content type (TRUE).',
335 'type' => 'int',
336 'not null' => TRUE,
337 'default' => 0,
338 'size' => 'tiny',
339 ),
340 'modified' => array(
341 'description' => 'A boolean indicating whether this type has been modified by an administrator; currently not used in any way.',
342 'type' => 'int',
343 'not null' => TRUE,
344 'default' => 0,
345 'size' => 'tiny',
346 ),
347 'locked' => array(
348 'description' => 'A boolean indicating whether the administrator can change the machine name of this type.',
349 'type' => 'int',
350 'not null' => TRUE,
351 'default' => 0,
352 'size' => 'tiny',
353 ),
354 'disabled' => array(
355 'description' => 'A boolean indicating whether the node type is disabled.',
356 'type' => 'int',
357 'not null' => TRUE,
358 'default' => 0,
359 'size' => 'tiny'
360 ),
361 'orig_type' => array(
362 '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.',
363 'type' => 'varchar',
364 'length' => 255,
365 'not null' => TRUE,
366 'default' => '',
367 ),
368 ),
369 'primary key' => array('type'),
370 );
371
372 $schema['block_node_type'] = array(
373 'description' => 'Sets up display criteria for blocks based on content types',
374 'fields' => array(
375 'module' => array(
376 'type' => 'varchar',
377 'length' => 64,
378 'not null' => TRUE,
379 'description' => "The block's origin module, from {block}.module.",
380 ),
381 'delta' => array(
382 'type' => 'varchar',
383 'length' => 32,
384 'not null' => TRUE,
385 'description' => "The block's unique delta within module, from {block}.delta.",
386 ),
387 'type' => array(
388 'type' => 'varchar',
389 'length' => 32,
390 'not null' => TRUE,
391 'description' => "The machine-readable name of this type from {node_type}.type.",
392 ),
393 ),
394 'primary key' => array('module', 'delta', 'type'),
395 'indexes' => array(
396 'type' => array('type'),
397 ),
398 );
399
400 $schema['history'] = array(
401 'description' => 'A record of which {users} have read which {node}s.',
402 'fields' => array(
403 'uid' => array(
404 'description' => 'The {users}.uid that read the {node} nid.',
405 'type' => 'int',
406 'not null' => TRUE,
407 'default' => 0,
408 ),
409 'nid' => array(
410 'description' => 'The {node}.nid that was read.',
411 'type' => 'int',
412 'not null' => TRUE,
413 'default' => 0,
414 ),
415 'timestamp' => array(
416 'description' => 'The Unix timestamp at which the read occurred.',
417 'type' => 'int',
418 'not null' => TRUE,
419 'default' => 0,
420 ),
421 ),
422 'primary key' => array('uid', 'nid'),
423 'indexes' => array(
424 'nid' => array('nid'),
425 ),
426 );
427
428 return $schema;
429 }
430
431 /**
432 * Implements hook_install().
433 */
434 function node_install() {
435 // Populate the node access table.
436 db_insert('node_access')
437 ->fields(array(
438 'nid' => 0,
439 'gid' => 0,
440 'realm' => 'all',
441 'grant_view' => 1,
442 'grant_update' => 0,
443 'grant_delete' => 0,
444 ))
445 ->execute();
446 }
447
448 /**
449 * Implements hook_update_dependencies().
450 */
451 function node_update_dependencies() {
452 // node_update_7006() migrates node data to fields and therefore must run
453 // after all Field modules have been enabled, which happens in
454 // system_update_7027(). It also needs to query the {filter_format} table to
455 // get a list of existing text formats, so it must run after
456 // filter_update_7000(), which creates that table.
457 $dependencies['node'][7006] = array(
458 'system' => 7027,
459 'filter' => 7000,
460 );
461
462 // node_update_7008() migrates role permissions and therefore must run after
463 // the {role} and {role_permission} tables are properly set up, which happens
464 // in user_update_7007().
465 $dependencies['node'][7008] = array(
466 'user' => 7007,
467 );
468
469 return $dependencies;
470 }
471
472 /**
473 * Utility function: fetch the node types directly from the database.
474 *
475 * This function is valid for a database schema version 7000.
476 *
477 * @ingroup update_api
478 */
479 function _update_7000_node_get_types() {
480 $node_types = db_query('SELECT * FROM {node_type}')->fetchAllAssoc('type', PDO::FETCH_OBJ);
481
482 // Create default settings for orphan nodes.
483 $all_types = db_query('SELECT DISTINCT type FROM {node}')->fetchCol();
484 $extra_types = array_diff($all_types, array_keys($node_types));
485
486 foreach ($extra_types as $type) {
487 $type_object = new stdClass();
488 $type_object->type = $type;
489
490 // In Drupal 6, whether you have a body field or not is a flag in the node
491 // type table. If it's enabled, nodes may or may not have an empty string
492 // for the bodies. As we can't detect what this setting should be in
493 // Drupal 7 without access to the Drupal 6 node type settings, we assume
494 // the default, which is to enable the body field.
495 $type_object->has_body = 1;
496 $type_object->body_label = 'Body';
497 $node_types[$type_object->type] = $type_object;
498 }
499 return $node_types;
500 }
501
502 /**
503 * @addtogroup updates-6.x-to-7.x
504 * @{
505 */
506
507 /**
508 * Upgrade the node type table and fix node type 'module' attribute to avoid name-space conflicts.
509 */
510 function node_update_7000() {
511 // Rename the module column to base.
512 db_change_field('node_type', 'module', 'base', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE));
513
514 db_add_field('node_type', 'module', array(
515 'description' => 'The module defining this node type.',
516 'type' => 'varchar',
517 'default' => '',
518 'length' => 255,
519 'not null' => TRUE,
520 ));
521
522 db_add_field('node_type', 'disabled', array(
523 'description' => 'A boolean indicating whether the node type is disabled.',
524 'type' => 'int',
525 'not null' => TRUE,
526 'default' => 0,
527 'size' => 'tiny'
528 ));
529
530 $modules = db_select('system', 's')
531 ->fields('s', array('name'))
532 ->condition('type', 'module');
533 db_update('node_type')
534 ->expression('module', 'base')
535 ->condition('base', $modules, 'IN')
536 ->execute();
537
538 db_update('node_type')
539 ->fields(array('base' => 'node_content'))
540 ->condition('base', 'node')
541 ->execute();
542 }
543
544 /**
545 * Rename {node_revisions} table to {node_revision}.
546 */
547 function node_update_7001() {
548 db_rename_table('node_revisions', 'node_revision');
549 }
550
551 /**
552 * Extend the node_promote_status index to include all fields required for the node page query.
553 */
554 function node_update_7002() {
555 db_drop_index('node', 'node_promote_status');
556 db_add_index('node', 'node_frontpage', array('promote', 'status', 'sticky', 'created'));
557 }
558
559 /**
560 * Remove the node_counter if the statistics module is uninstalled.
561 */
562 function node_update_7003() {
563 if (drupal_get_installed_schema_version('statistics') == SCHEMA_UNINSTALLED) {
564 db_drop_table('node_counter');
565 }
566 }
567
568 /**
569 * Extend the existing default preview and teaser settings to all node types.
570 */
571 function node_update_7004() {
572 // Get original settings and all types.
573 $original_length = variable_get('teaser_length', 600);
574 $original_preview = variable_get('node_preview', 0);
575
576 // Map old preview setting to new values order.
577 $original_preview ? $original_preview = 2 : $original_preview = 1;
578 node_type_cache_reset();
579
580 // Apply original settings to all types.
581 foreach (_update_7000_node_get_types() as $type => $type_object) {
582 variable_set('teaser_length_' . $type, $original_length);
583 variable_set('node_preview_' . $type, $original_preview);
584 }
585 // Delete old variable but leave 'teaser_length' for aggregator module upgrade.
586 variable_del('node_preview');
587 }
588
589 /**
590 * Add status/comment/promote and sticky columns to the {node_revision} table.
591 */
592 function node_update_7005() {
593 foreach (array('status', 'comment', 'promote', 'sticky') as $column) {
594 db_add_field('node_revision', $column, array(
595 'type' => 'int',
596 'not null' => TRUE,
597 'default' => 0,
598 ));
599 }
600 }
601
602 /**
603 * Convert body and teaser from node properties to fields, and migrate status/comment/promote and sticky columns to the {node_revision} table.
604 */
605 function node_update_7006(&$sandbox) {
606 $sandbox['#finished'] = 0;
607
608 // Get node type info for every invocation.
609 node_type_cache_reset();
610
611 if (!isset($sandbox['total'])) {
612 // Initial invocation.
613
614 // First, create the body field.
615 $body_field = array(
616 'field_name' => 'body',
617 'type' => 'text_with_summary',
618 'module' => 'text',
619 'cardinality' => 1,
620 'entity_types' => array('node'),
621 'translatable' => TRUE,
622 );
623 _update_7000_field_create_field($body_field);
624
625 $default_trim_length = variable_get('teaser_length', 600);
626
627 // Get node type info, specifically the body field settings.
628 $node_types = _update_7000_node_get_types();
629
630 // Add body field instances for existing node types.
631 foreach ($node_types as $node_type) {
632 if ($node_type->has_body) {
633 $trim_length = variable_get('teaser_length_' . $node_type->type, $default_trim_length);
634
635 $instance = array(
636 'entity_type' => 'node',
637 'bundle' => $node_type->type,
638 'label' => $node_type->body_label,
639 'description' => isset($node_type->description) ? $node_type->description : '',
640 'required' => (isset($node_type->min_word_count) && $node_type->min_word_count > 0) ? 1 : 0,
641 'widget' => array(
642 'type' => 'text_textarea_with_summary',
643 'settings' => array(
644 'rows' => 20,
645 'summary_rows' => 5,
646 ),
647 'weight' => -4,
648 'module' => 'text',
649 ),
650 'settings' => array('display_summary' => TRUE),
651 'display' => array(
652 'default' => array(
653 'label' => 'hidden',
654 'type' => 'text_default',
655 ),
656 'teaser' => array(
657 'label' => 'hidden',
658 'type' => 'text_summary_or_trimmed',
659 'trim_length' => $trim_length,
660 ),
661 ),
662 );
663 _update_7000_field_create_instance($body_field, $instance);
664 variable_del('teaser_length_' . $node_type->type);
665 }
666 // Leave 'teaser_length' variable for aggregator module upgrade.
667
668 $sandbox['node_types_info'][$node_type->type] = array(
669 'has_body' => $node_type->has_body,
670 );
671 }
672
673 // Used below when updating the stored text format of each node body.
674 $sandbox['existing_text_formats'] = db_query("SELECT format FROM {filter_format}")->fetchCol();
675
676 // Initialize state for future calls.
677 $sandbox['last'] = 0;
678 $sandbox['count'] = 0;
679
680 $query = db_select('node', 'n');
681 $query->join('node_revision', 'nr', 'n.nid = nr.nid');
682 $sandbox['total'] = $query->countQuery()->execute()->fetchField();
683
684 $sandbox['body_field_id'] = $body_field['id'];
685 }
686 else {
687 // Subsequent invocations.
688
689 $found = FALSE;
690 if ($sandbox['total']) {
691 // Operate on every revision of every node (whee!), in batches.
692 $batch_size = 200;
693 $query = db_select('node_revision', 'nr');
694 $query->innerJoin('node', 'n', 'n.nid = nr.nid');
695 $query
696 ->fields('nr', array('nid', 'vid', 'body', 'teaser', 'format'))
697 ->fields('n', array('type', 'status', 'comment', 'promote', 'sticky', 'language'))
698 ->condition('nr.vid', $sandbox['last'], '>')
699 ->orderBy('nr.vid', 'ASC')
700 ->range(0, $batch_size);
701 $revisions = $query->execute();
702
703 // Load each revision of each node, set up 'body'
704 // appropriately, and save the node's field data. Note that
705 // node_load() will not return the body or teaser values from
706 // {node_revision} because those columns have been removed from the
707 // schema structure in memory (but not yet from the database),
708 // so we get the values from the explicit query of the table
709 // instead.
710 foreach ($revisions as $revision) {
711 $found = TRUE;
712
713 if ($sandbox['node_types_info'][$revision->type]['has_body']) {
714 $node = (object) array(
715 'nid' => $revision->nid,
716 'vid' => $revision->vid,
717 'type' => $revision->type,
718 );
719 // After node_update_7009() we will always have LANGUAGE_NONE as
720 // language neutral language code, but here we still have empty
721 // strings.
722 $langcode = empty($revision->language) ? LANGUAGE_NONE : $revision->language;
723 if (!empty($revision->teaser) && $revision->teaser != text_summary($revision->body)) {
724 $node->body[$langcode][0]['summary'] = $revision->teaser;
725 }
726 // Do this after text_summary() above.
727 $break = '<!--break-->';
728 if (substr($revision->body, 0, strlen($break)) == $break) {
729 $revision->body = substr($revision->body, strlen($break));
730 }
731 $node->body[$langcode][0]['value'] = $revision->body;
732 // Update the revision's text format for the changes to the Drupal 7
733 // filter system. This uses the same kind of logic that occurs, for
734 // example, in user_update_7010(), but we do this here rather than
735 // via a separate set of database queries, since we are already
736 // migrating the data.
737 if (empty($revision->body) && empty($revision->format)) {
738 $node->body[$langcode][0]['format'] = NULL;
739 }
740 elseif (!in_array($revision->format, $sandbox['existing_text_formats'])) {
741 $node->body[$langcode][0]['format'] = variable_get('filter_default_format', 1);
742 }
743 else {
744 $node->body[$langcode][0]['format'] = $revision->format;
745 }
746 // This is a core update and no contrib modules are enabled yet, so
747 // we can assume default field storage for a faster update.
748 _update_7000_field_sql_storage_write('node', $node->type, $node->nid, $node->vid, 'body', $node->body);
749 }
750
751 // Migrate the status columns to the {node_revision} table.
752 db_update('node_revision')
753 ->fields(array(
754 'status' => $revision->status,
755 'comment' => $revision->comment,
756 'promote' => $revision->promote,
757 'sticky' => $revision->sticky,
758 ))
759 ->condition('vid', $revision->vid)
760 ->execute();
761
762 $sandbox['last'] = $revision->vid;
763 $sandbox['count'] += 1;
764 }
765
766 $sandbox['#finished'] = min(0.99, $sandbox['count'] / $sandbox['total']);
767 }
768
769 if (!$found) {
770 // All nodes are processed.
771
772 // Remove the now-obsolete body info from node_revision.
773 db_drop_field('node_revision', 'body');
774 db_drop_field('node_revision', 'teaser');
775 db_drop_field('node_revision', 'format');
776
777 // Remove node_type properties related to the former 'body'.
778 db_drop_field('node_type', 'has_body');
779 db_drop_field('node_type', 'body_label');
780
781 // We're done.
782 $sandbox['#finished'] = 1;
783 }
784 }
785 }
786
787 /**
788 * Remove column min_word_count.
789 */
790 function node_update_7007() {
791 db_drop_field('node_type', 'min_word_count');
792 }
793
794 /**
795 * Split the 'administer nodes' permission from 'access content overview'.
796 */
797 function node_update_7008() {
798 $roles = user_roles(FALSE, 'administer nodes');
799 foreach ($roles as $rid => $role) {
800 _update_7000_user_role_grant_permissions($rid, array('access content overview'), 'node');
801 }
802 }
803
804 /**
805 * Convert node languages from the empty string to LANGUAGE_NONE.
806 */
807 function node_update_7009() {
808 db_update('node')
809 ->fields(array('language' => LANGUAGE_NONE))
810 ->condition('language', '')
811 ->execute();
812 }
813
814 /**
815 * Add the {block_node_type} table.
816 */
817 function node_update_7010() {
818 $schema['block_node_type'] = array(
819 'description' => 'Sets up display criteria for blocks based on content types',
820 'fields' => array(
821 'module' => array(
822 'type' => 'varchar',
823 'length' => 64,
824 'not null' => TRUE,
825 'description' => "The block's origin module, from {block}.module.",
826 ),
827 'delta' => array(
828 'type' => 'varchar',
829 'length' => 32,
830 'not null' => TRUE,
831 'description' => "The block's unique delta within module, from {block}.delta.",
832 ),
833 'type' => array(
834 'type' => 'varchar',
835 'length' => 32,
836 'not null' => TRUE,
837 'description' => "The machine-readable name of this type from {node_type}.type.",
838 ),
839 ),
840 'primary key' => array('module', 'delta', 'type'),
841 'indexes' => array(
842 'type' => array('type'),
843 ),
844 );
845
846 db_create_table('block_node_type', $schema['block_node_type']);
847 }
848
849 /**
850 * @} End of "addtogroup updates-6.x-to-7.x".
851 */
852
853 /**
854 * @addtogroup updates-7.x-extra
855 * @{
856 */
857
858 /**
859 * Update the database from Drupal 6 to match the schema.
860 */
861 function node_update_7011() {
862 // Drop node moderation field.
863 db_drop_field('node', 'moderate');
864 db_drop_index('node', 'node_moderate');
865
866 // Change {node_revision}.status field to default to 1.
867 db_change_field('node_revision', 'status', 'status', array(
868 'type' => 'int',
869 'not null' => TRUE,
870 'default' => 1,
871 ));
872
873 // Change {node_type}.module field default.
874 db_change_field('node_type', 'module', 'module', array(
875 'type' => 'varchar',
876 'length' => 255,
877 'not null' => TRUE,
878 ));
879 }
880
881 /**
882 * Switches body fields to untranslatable while upgrading from D6 and makes them language neutral.
883 */
884 function node_update_7012() {
885 // If we are upgrading from D6, then body fields should be set back to
886 // untranslatable, as D6 did not know about the idea of translating fields,
887 // but only nodes. If a D7 > D7 update is running we need to skip this update,
888 // as it is a valid use case to have translatable body fields in this context.
889 if (variable_get('update_d6', FALSE)) {
890 // Make node bodies untranslatable: field_update_field() cannot be used
891 // throughout the upgrade process and we do not have an update counterpart
892 // for _update_7000_field_create_field(). Hence we are forced to update the
893 // 'field_config' table directly. This is a safe operation since it is
894 // being performed while upgrading from D6. Perfoming the same operation
895 // during a D7 update is highly discouraged.
896 db_update('field_config')
897 ->fields(array('translatable' => 0))
898 ->condition('field_name', 'body')
899 ->execute();
900
901 // Switch field languages to LANGUAGE_NONE, since initially they were
902 // assigned the node language.
903 foreach (array('field_data_body', 'field_revision_body') as $table) {
904 db_update($table)
905 ->fields(array('language' => LANGUAGE_NONE))
906 ->execute();
907 }
908
909 node_type_cache_reset();
910 }
911 }
912
913 /**
914 * Change {node}.vid default value from 0 to NULL to avoid deadlock issues on MySQL.
915 */
916 function node_update_7013() {
917 db_drop_unique_key('node', 'vid');
918 db_change_field('node', 'vid', 'vid', array(
919 'description' => 'The current {node_revision}.vid version identifier.',
920 'type' => 'int',
921 'unsigned' => TRUE,
922 'not null' => FALSE,
923 'default' => NULL,
924 ));
925 db_add_unique_key('node', 'vid', array('vid'));
926 }
927
928 /**
929 * @} End of "addtogroup updates-7.x-extra".
930 */