node.install 34.5 KB
Newer Older
1
2
<?php

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

8
use Drupal\Component\Uuid\Uuid;
9
10
use Drupal\Core\Language\Language;

11
/**
12
 * Implements hook_schema().
13
14
15
 */
function node_schema() {
  $schema['node'] = array(
16
    'description' => 'The base table for nodes.',
17
    'fields' => array(
18
      'nid' => array(
19
        'description' => 'The primary identifier for a node.',
20
21
        'type' => 'serial',
        'unsigned' => TRUE,
22
23
        'not null' => TRUE,
      ),
24
25
26
27
28
29
      'uuid' => array(
        'description' => 'Unique Key: Universally unique identifier for this entity.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => FALSE,
      ),
30
31
      // Defaults to NULL in order to avoid a brief period of potential
      // deadlocks on the index.
32
      'vid' => array(
33
        'description' => 'The current {node_field_revision}.vid version identifier.',
34
35
        'type' => 'int',
        'unsigned' => TRUE,
36
37
        'not null' => FALSE,
        'default' => NULL,
38
      ),
39
      'type' => array(
40
        'description' => 'The type of this node.',
41
42
43
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
44
45
        'default' => '',
      ),
46
      'langcode' => array(
47
        'description' => 'The {language}.langcode of this node.',
48
49
50
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
51
52
        'default' => '',
      ),
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
      // @todo Remove the following columns when removing the legacy Content
      //   Translation module. See http://drupal.org/node/1952062.
      'tnid' => array(
        'description' => 'The translation set ID for this node, which equals the node ID of the source post in each set.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'translate' => array(
        'description' => 'A boolean indicating whether this translation page needs to be updated.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'node_type' => array(array('type', 4)),
      'tnid' => array('tnid'),
      'translate' => array('translate'),
    ),
    'unique keys' => array(
      'vid' => array('vid'),
      'uuid' => array('uuid'),
    ),
    'foreign keys' => array(
      'node_revision' => array(
        'table' => 'node_field_revision',
        'columns' => array('vid' => 'vid'),
      ),
    ),
    'primary key' => array('nid'),
  );

  // Node field storage.
  $schema['node_field_data'] = array(
    'description' => 'Base table for node properties.',
    'fields' => array(
      'nid' => array(
        'description' => 'The primary identifier for a node.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'vid' => array(
        'description' => 'The current {node_field_revision}.vid version identifier.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'type' => array(
        'description' => 'The {node_type}.type of this node.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'langcode' => array(
        'description' => 'The {language}.langcode of these node property values.',
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
      ),
      'default_langcode' => array(
        'description' => 'Boolean indicating whether the property values are in the {language}.langcode of this node.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 1,
      ),
123
      'title' => array(
124
        'description' => 'The title of this node, always treated as non-markup plain text.',
125
126
127
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
128
129
        'default' => '',
      ),
130
      'uid' => array(
131
        'description' => 'The {users}.uid that owns this node; initially, this is the user that created it.',
132
        'type' => 'int',
133
        'unsigned' => TRUE,
134
        'not null' => TRUE,
135
136
        'default' => 0,
      ),
137
      'status' => array(
138
        'description' => 'Boolean indicating whether the node translation is published (visible to non-administrators).',
139
140
        'type' => 'int',
        'not null' => TRUE,
141
142
        'default' => 1,
      ),
143
      'created' => array(
144
        'description' => 'The Unix timestamp when the node translation was created.',
145
146
        'type' => 'int',
        'not null' => TRUE,
147
148
        'default' => 0,
      ),
149
      'changed' => array(
150
        'description' => 'The Unix timestamp when the node translation was most recently saved.',
151
152
        'type' => 'int',
        'not null' => TRUE,
153
154
        'default' => 0,
      ),
155
      'comment' => array(
156
        'description' => 'Whether comments are allowed on this node translation: 0 = no, 1 = closed (read only), 2 = open (read/write).',
157
158
        'type' => 'int',
        'not null' => TRUE,
159
160
        'default' => 0,
      ),
161
      'promote' => array(
162
        'description' => 'Boolean indicating whether the node translation should be displayed on the front page.',
163
164
        'type' => 'int',
        'not null' => TRUE,
165
166
        'default' => 0,
      ),
167
      'sticky' => array(
168
        'description' => 'Boolean indicating whether the node translation should be displayed at the top of lists in which it appears.',
169
170
        'type' => 'int',
        'not null' => TRUE,
171
        'default' => 0,
172
      ),
173
    ),
174
    'indexes' => array(
175
176
177
178
179
180
181
182
183
      'node_changed' => array('changed'),
      'node_created' => array('created'),
      'node_default_langcode' => array('default_langcode'),
      'node_langcode' => array('langcode'),
      'node_frontpage' => array('promote', 'status', 'sticky', 'created'),
      'node_status_type' => array('status', 'type', 'nid'),
      'node_title_type' => array('title', array('type', 4)),
      'node_type' => array(array('type', 4)),
      'nid' => array('nid'),
184
      'vid' => array('vid'),
185
      'uid' => array('uid'),
186
    ),
187
    'foreign keys' => array(
188
189
190
      'node_base' => array(
        'table' => 'node',
        'columns' => array('nid' => 'nid'),
191
192
193
194
195
      ),
      'node_author' => array(
        'table' => 'users',
        'columns' => array('uid' => 'uid'),
      ),
196
    ),
197
    'primary key' => array('nid', 'vid', 'langcode'),
198
  );
199

200
201
  $schema['node_field_revision'] = array(
    'description' => 'Stores information about each saved version of a {node}.',
202
    'fields' => array(
203
      'nid' => array(
204
        'description' => 'The {node} this version belongs to.',
205
206
207
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
208
209
210
211
212
213
      ),
      'vid' => array(
        'description' => 'The primary identifier for this version.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
214
      ),
215
      'langcode' => array(
216
        'description' => 'The {language}.langcode of this version.',
217
218
219
220
221
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
      ),
222
223
      'default_langcode' => array(
        'description' => 'Boolean indicating whether the property values of this version are in the {language}.langcode of this node.',
224
225
226
227
        'type' => 'int',
        'not null' => TRUE,
        'default' => 1,
      ),
228
229
230
231
232
233
234
235
236
237
238
239
240
241
      'log' => array(
        'description' => 'The log entry explaining the changes in this version.',
        'type' => 'text',
        'not null' => FALSE,
        'size' => 'big',
      ),
      'revision_timestamp' => array(
        'description' => 'The Unix timestamp when the version was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'revision_uid' => array(
        'description' => 'The {users}.uid that created this version.',
242
243
244
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
245
246
        'default' => 0,
      ),
247
248
      'title' => array(
        'description' => 'The title of this version, always treated as non-markup plain text.',
249
250
251
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
252
253
        'default' => '',
      ),
254
255
      'uid' => array(
        'description' => 'The {users}.uid that created this node.',
256
257
258
259
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
260
      ),
261
262
263
264
265
266
267
268
      'status' => array(
        'description' => 'Boolean indicating whether the node (at the time of this revision) is published (visible to non-administrators).',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 1,
      ),
      'created' => array(
        'description' => 'The Unix timestamp when the node was created.',
269
270
271
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
272
      ),
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
      'changed' => array(
        'description' => 'The Unix timestamp when the version was most recently saved.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'comment' => array(
        'description' => 'Whether comments are allowed on this node (at the time of this revision): 0 = no, 1 = closed (read only), 2 = open (read/write).',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'promote' => array(
        'description' => 'Boolean indicating whether the node (at the time of this revision) should be displayed on the front page.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'sticky' => array(
        'description' => 'Boolean indicating whether the node (at the time of this revision) should be displayed at the top of lists in which it appears.',
293
294
295
296
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
297
    ),
298
299
300
301
302
303
304
305
    'indexes' => array(
      'nid' => array('nid'),
      'uid' => array('uid'),
      'revision_uid' => array('revision_uid'),
      'vid' => array('vid'),
      'node_default_langcode' => array('default_langcode'),
      'node_langcode' => array('langcode'),
    ),
306
    'foreign keys' => array(
307
      'versioned_node' => array(
308
309
310
        'table' => 'node',
        'columns' => array('nid' => 'nid'),
      ),
311
312
313
314
315
316
      'version_author' => array(
        'table' => 'users',
        'columns' => array('uid' => 'uid'),
      ),
    ),
    'primary key' => array('nid', 'vid', 'langcode'),
317
  );
318

319
320
  $schema['node_access'] = array(
    'description' => 'Identifies which realm/grant pairs a user must possess in order to view, update, or delete specific nodes.',
321
    'fields' => array(
322
      'nid' => array(
323
        'description' => 'The {node}.nid this record affects.',
324
325
326
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
327
328
        'default' => 0,
      ),
329
330
331
332
333
334
335
336
337
338
      'langcode' => array(
        'description' => 'The {language}.langcode of this node.',
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
      ),
      'fallback' => array(
        'description' => 'Boolean indicating whether this record should be used as a fallback if a language condition is not provided.',
        'type' => 'int',
339
        'unsigned' => TRUE,
340
        'not null' => TRUE,
341
        'default' => 1,
342
      ),
343
344
      'gid' => array(
        'description' => "The grant ID a user must possess in the specified realm to gain this row's privileges on the node.",
345
        'type' => 'int',
346
        'unsigned' => TRUE,
347
        'not null' => TRUE,
348
349
        'default' => 0,
      ),
350
351
      'realm' => array(
        'description' => 'The realm in which the user must possess the grant ID. Each node access node can define one or more realms.',
352
353
354
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
355
356
        'default' => '',
      ),
357
358
      'grant_view' => array(
        'description' => 'Boolean indicating whether a user with the realm/grant pair can view this node.',
359
        'type' => 'int',
360
        'unsigned' => TRUE,
361
362
        'not null' => TRUE,
        'default' => 0,
363
        'size' => 'tiny',
364
      ),
365
366
      'grant_update' => array(
        'description' => 'Boolean indicating whether a user with the realm/grant pair can edit this node.',
367
        'type' => 'int',
368
        'unsigned' => TRUE,
369
370
        'not null' => TRUE,
        'default' => 0,
371
        'size' => 'tiny',
372
      ),
373
374
      'grant_delete' => array(
        'description' => 'Boolean indicating whether a user with the realm/grant pair can delete this node.',
375
        'type' => 'int',
376
        'unsigned' => TRUE,
377
378
        'not null' => TRUE,
        'default' => 0,
379
        'size' => 'tiny',
380
      ),
381
    ),
382
    'primary key' => array('nid', 'gid', 'realm', 'langcode'),
383
    'foreign keys' => array(
384
      'affected_node' => array(
385
386
387
        'table' => 'node',
        'columns' => array('nid' => 'nid'),
      ),
388
    ),
389
  );
390
391
392

  return $schema;
}
393

394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
/**
 * Implements hook_install().
 */
function node_install() {
  // Populate the node access table.
  db_insert('node_access')
    ->fields(array(
      'nid' => 0,
      'gid' => 0,
      'realm' => 'all',
      'grant_view' => 1,
      'grant_update' => 0,
      'grant_delete' => 0,
    ))
    ->execute();
}

411
412
/**
 * Implements hook_uninstall().
413
414
415
 *
 * @see node_ranking()
 * @see _node_rankings()
416
417
418
 */
function node_uninstall() {
  // Delete node type variables.
419
420
421
  $types = config_get_storage_names_with_prefix('node.type.');
  foreach ($types as $config_name) {
    $type = config($config_name)->get('type');
422
    config('language.settings')->clear('node. ' . $type . '.language.default_configuration')->save();
423
424
425
426
427
428
429
430
431
  }

  // Delete node search ranking variables.
  variable_del('node_rank_relevance');
  variable_del('node_rank_sticky');
  variable_del('node_rank_promote');
  variable_del('node_rank_recent');

  // Delete remaining general module variables.
432
  Drupal::state()->delete('node.node_access_needs_rebuild');
433
434
  variable_del('node_admin_theme');
  variable_del('node_recent_block_count');
435
436

  // Delete any stored state.
437
  Drupal::state()->delete('node.cron_last');
438
439
}

440
/**
441
 * Fetches node types directly from the database.
442
 *
443
 * @ingroup update_api
444
 */
445
function _update_7000_node_get_types() {
446
447
448
449
450
451
452
  $node_types = db_query('SELECT * FROM {node_type}')->fetchAllAssoc('type', PDO::FETCH_OBJ);

  // Create default settings for orphaned nodes.
  $all_types = db_query('SELECT DISTINCT type FROM {node}')->fetchCol();
  $extra_types = array_diff($all_types, array_keys($node_types));

  foreach ($extra_types as $type) {
453
    $type_object = new stdClass();
454
455
456
457
458
459
460
461
462
463
464
    $type_object->type = $type;
    // In Drupal 6, whether you have a body field or not is a flag in the node
    // type table. If it's enabled, nodes may or may not have an empty string
    // for the bodies. As we can't detect what this setting should be in
    // Drupal 7 without access to the Drupal 6 node type settings, we assume
    // the default, which is to enable the body field.
    $type_object->has_body = 1;
    $type_object->body_label = 'Body';
    $node_types[$type_object->type] = $type_object;
  }
  return $node_types;
465
}
466
467
468
469
470
471

/**
 * @addtogroup updates-7.x-to-8.x
 * @{
 */

472
473
474
475
476
477
478
479
480
/**
 * Implements hook_update_dependency().
 */
function node_update_dependency() {
  $dependencies['node'][8013] = array(
    'user' => 8002,
  );
}

481
482
483
484
/**
 * Rename node type language variable names.
 *
 * @see http://drupal.org/node/540294
485
486
 *
 * @ingroup config_upgrade
487
488
489
490
 */
function node_update_8001() {
  $types = db_query('SELECT type FROM {node_type}')->fetchCol();
  foreach ($types as $type) {
491
    $node_type_language = update_variable_get('language_content_type_' . $type);
492
    if (isset($node_type_language)) {
493
      update_variable_set('node_type_language_' . $type, $node_type_language);
494
    }
495
    update_variable_del('language_content_type_' . $type);
496
497
498
  }
}

499
500
501
502
503
504
505
506
507
508
509
510
511
512
/**
 * Rename node.language field to node.langcode.
 */
function node_update_8002() {
  $spec = array(
    'description' => 'The {language}.langcode of this node.',
    'type' => 'varchar',
    'length' => 12,
    'not null' => TRUE,
    'default' => '',
  );
  db_change_field('node', 'language', 'langcode', $spec);
}

513
/**
514
515
516
517
518
 * Rename node type language variable names.
 */
function node_update_8003() {
  $types = db_query('SELECT type FROM {node_type}')->fetchCol();
  foreach ($types as $type) {
519
    update_variable_set('node_type_language_default_' . $type, Language::LANGCODE_NOT_SPECIFIED);
520
    $node_type_language = update_variable_get('node_type_language_' . $type, 0);
521
    if ($node_type_language == 0) {
522
      update_variable_set('node_type_language_show_' . $type, FALSE);
523
524
525
526
    }
    if ($node_type_language == 2) {
      // Translation was enabled, so enable it again and
      // unhide the language selector. Because if language is
527
      // Language::LANGCODE_NOT_SPECIFIED and the selector hidden, translation
528
      // cannot be enabled.
529
      update_variable_set('node_type_language_show_' . $type, TRUE);
530
      update_variable_set('node_type_language_translation_enabled_' . $type, TRUE);
531
    }
532
    update_variable_del('node_type_language_' . $type);
533
534
535
  }
}

536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
/**
 * Create a UUID column for nodes.
 */
function node_update_8004() {
  $spec = array(
    'description' => 'Unique Key: Universally unique identifier for this entity.',
    'type' => 'varchar',
    'length' => 128,
    'not null' => FALSE,
  );
  $keys = array(
    'unique keys' => array(
      'uuid' => array('uuid'),
    ),
  );
  // Account for sites having the contributed UUID module installed.
  if (db_field_exists('node', 'uuid')) {
    db_change_field('node', 'uuid', 'uuid', $spec, $keys);
  }
  else {
    db_add_field('node', 'uuid', $spec, $keys);
  }
}

560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
/**
 * Make *id fields unsigned.
 */
function node_update_8005() {
  db_drop_index('node', 'uid');
  db_change_field('node', 'uid', 'uid',
    array(
      'description' => 'The {users}.uid that owns this node; initially, this is the user that created it.',
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
    ),
    array('indexes' => array(
      'uid' => array('uid'),
    ))
  );

  db_drop_index('node_revision', 'uid');
  db_change_field('node_revision', 'uid', 'uid',
    array(
      'description' => 'The {users}.uid that created this version.',
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
    ),
    array('indexes' => array(
      'uid' => array('uid'),
    ))
  );

  db_drop_primary_key('history');
  db_drop_index('history', 'nid');
  db_change_field('history', 'uid', 'uid',
    array(
      'description' => 'The {users}.uid that read the {node} nid.',
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
    )
  );
  db_change_field('history', 'nid', 'nid',
    array(
      'description' => 'The {node}.nid that was read.',
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
    ),
    array('primary key' => array('uid', 'nid'), 'indexes' => array(
      'nid' => array('nid'),
    ))
  );
}

617
/**
618
 * Generate a UUID for all nodes.
619
620
621
622
623
624
625
626
627
628
629
630
631
632
 */
function node_update_8006(&$sandbox) {
  if (!isset($sandbox['progress'])) {
    $sandbox['progress'] = 0;
    $sandbox['last'] = 0;
    $sandbox['max'] = db_query('SELECT COUNT(nid) FROM {node} WHERE uuid IS NULL')->fetchField();
  }

  $nids = db_query_range('SELECT nid FROM {node} WHERE nid > :nid AND uuid IS NULL ORDER BY nid ASC', 0, 10, array(':nid' => $sandbox['last']))->fetchCol();
  update_add_uuids($sandbox, 'node', 'nid', $nids);

  $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
}

633
634
635
636
637
638
639
/**
 * Move the language default values to config.
 */
function node_update_8007() {
  $types = db_query('SELECT type FROM {node_type}')->fetchCol();
  foreach ($types as $type) {
    $language_default = update_variable_get('node_type_language_default_' . $type, NULL);
640
641
642
    $language_show = update_variable_get('node_type_language_show_' . $type, NULL);
    if (isset($language_default) || isset($language_show)) {
      $values = array('langcode' => $language_default, 'language_show' => $language_show);
643
644
645
646
647
      config('language.settings')->set('node.' . $type . '.language.default_configuration', $values)->save();
    }
  }
}

648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
/**
 * Rename default menu names.
 */
function node_update_8008() {
  // System menu's new block deltas are prefixed with 'menu-'.
  $map = array(
    'navigation' => 'menu-tools',
    'management' => 'menu-admin',
    'user-menu' => 'menu-account',
    'main-menu' => 'menu-main',
  );
  foreach ($map as $old => $new) {
    db_update('block_node_type')
      ->condition('module', 'system')
      ->condition('delta', $old)
      ->fields(array('delta' => $new))
      ->execute();
  }
}

668
669
670
671
672
673
674
675
676
/**
 * Coverts default_nodes_main variable to config.
 *
 * @ingroup config_upgrade
 */
function node_update_8009() {
  update_variables_to_config('node.settings', array('default_nodes_main' => 'items_per_page'));
}

677
678
679
680
681
/**
 * Moves node_access_needs_rebuild from variable to state.
 *
 * @ingroup config_upgrade
 */
webchick's avatar
webchick committed
682
function node_update_8010() {
683
684
685
  update_variables_to_state(array('node_access_needs_rebuild' => 'node.node_access_needs_rebuild'));
}

686
687
688
689
690
691
692
693
694
/**
 * Moves node cron last run time from variable to state.
 *
 * @ingroup config_upgrade
 */
function node_update_8011() {
  update_variables_to_state(array('node_cron_last' =>'node.cron_last'));
}

695
696
697
698
699
/**
 * Enable History module.
 */
function node_update_8012() {
  // Enable the history module without re-installing the schema.
700
  module_enable(array('history'));
701
702
}

703
704
705
706
/**
 * Renames global revision permissions to use the word 'all'.
 */
function node_update_8013() {
707
708
709
710
711
  update_replace_permissions(array(
    'view revisions' => array('view all revisions'),
    'revert revisions' => array('revert all revisions'),
    'delete revisions' => array('delete all revisions'),
  ));
712
713
}

714
/**
715
 * Empty update. See https://drupal.org/node/2006484.
716
717
718
719
 */
function node_update_8014() {
}

720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
/**
 * Add language support to the {node_access} table.
 */
function node_update_8015() {
  // Add the langcode field.
  $langcode_field = array(
    'type' => 'varchar',
    'length' => 12,
    'not null' => TRUE,
    'default' => '',
    'description' => 'The {language}.langcode of this node.',
  );
  db_add_field('node_access', 'langcode', $langcode_field);

  // Add the fallback field.
  $fallback_field = array(
    'description' => 'Boolean indicating whether this record should be used as a fallback if a language condition is not provided.',
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 1,
  );
  db_add_field('node_access', 'fallback', $fallback_field);

  db_drop_primary_key('node_access');
  db_add_primary_key('node_access', array('nid', 'gid', 'realm', 'langcode'));
}

748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
 * Upgrade node schema to the standard entity SQL schema: schema definition.
 */
function _node_update_8016_schema() {
  $schema = array();

  $schema['node_field_data'] = array(
    'description' => 'Base table for node properties.',
    'fields' => array(
      'nid' => array(
        'description' => 'The primary identifier for a node.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'vid' => array(
        'description' => 'The current {node_field_revision}.vid version identifier.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'type' => array(
        'description' => 'The {node_type}.type of this node.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'langcode' => array(
        'description' => 'The {language}.langcode of these node property values.',
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
      ),
      'default_langcode' => array(
        'description' => 'Boolean indicating whether the property values are in the {language}.langcode of this node.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 1,
      ),
      'title' => array(
        'description' => 'The title of this node, always treated as non-markup plain text.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'uid' => array(
        'description' => 'The {users}.uid that owns this node; initially, this is the user that created it.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'status' => array(
        'description' => 'Boolean indicating whether the node translation is published (visible to non-administrators).',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 1,
      ),
      'created' => array(
        'description' => 'The Unix timestamp when the node translation was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'changed' => array(
        'description' => 'The Unix timestamp when the node translation was most recently saved.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'comment' => array(
        'description' => 'Whether comments are allowed on this node translation: 0 = no, 1 = closed (read only), 2 = open (read/write).',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'promote' => array(
        'description' => 'Boolean indicating whether the node translation should be displayed on the front page.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'sticky' => array(
        'description' => 'Boolean indicating whether the node translation should be displayed at the top of lists in which it appears.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'node_changed' => array('changed'),
      'node_created' => array('created'),
      'node_frontpage' => array('promote', 'status', 'sticky', 'created'),
      'node_status_type' => array('status', 'type', 'nid'),
      'node_title_type' => array('title', array('type', 4)),
      'node_type' => array(array('type', 4)),
      'nid' => array('nid'),
      'vid' => array('vid'),
      'uid' => array('uid'),
    ),
    'foreign keys' => array(
      'node_base' => array(
        'table' => 'node',
        'columns' => array('nid' => 'nid'),
      ),
      'node_author' => array(
        'table' => 'users',
        'columns' => array('uid' => 'uid'),
      ),
    ),
    'primary key' => array('nid', 'vid', 'langcode'),
  );

  $schema['node_field_revision'] = array(
    'description' => 'Stores information about each saved version of a {node}.',
    'fields' => array(
      'nid' => array(
        'description' => 'The {node} this version belongs to.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'vid' => array(
        'description' => 'The primary identifier for this version.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'langcode' => array(
        'description' => 'The {language}.langcode of this version.',
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
      ),
      'default_langcode' => array(
        'description' => 'Boolean indicating whether the property values of this version are in the {language}.langcode of this node.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 1,
      ),
      'log' => array(
        'description' => 'The log entry explaining the changes in this version.',
        'type' => 'text',
        'not null' => FALSE,
        'size' => 'big',
      ),
      'revision_timestamp' => array(
        'description' => 'The Unix timestamp when the version was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'revision_uid' => array(
        'description' => 'The {users}.uid that created this version.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'title' => array(
        'description' => 'The title of this version, always treated as non-markup plain text.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'uid' => array(
        'description' => 'The {users}.uid that created this node.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'status' => array(
        'description' => 'Boolean indicating whether the node (at the time of this revision) is published (visible to non-administrators).',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 1,
      ),
      'created' => array(
        'description' => 'The Unix timestamp when the node was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'changed' => array(
        'description' => 'The Unix timestamp when the version was most recently saved.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'comment' => array(
        'description' => 'Whether comments are allowed on this node (at the time of this revision): 0 = no, 1 = closed (read only), 2 = open (read/write).',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'promote' => array(
        'description' => 'Boolean indicating whether the node (at the time of this revision) should be displayed on the front page.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'sticky' => array(
        'description' => 'Boolean indicating whether the node (at the time of this revision) should be displayed at the top of lists in which it appears.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'nid' => array('nid'),
      'uid' => array('uid'),
      'revision_uid' => array('revision_uid'),
      'vid' => array('vid'),
    ),
    'foreign keys' => array(
      'versioned_node' => array(
        'table' => 'node',
        'columns' => array('nid' => 'nid'),
      ),
      'version_author' => array(
        'table' => 'users',
        'columns' => array('uid' => 'uid'),
      ),
    ),
    'primary key' => array('nid', 'vid', 'langcode'),
  );

  return $schema;
}

/**
 * Upgrade node schema to the standard entity SQL schema: create new tables.
 */
function node_update_8016() {
  foreach (_node_update_8016_schema() as $table => $table_schema) {
    db_create_table($table, $table_schema);
  }
}

/**
 * Upgrade node schema to the standard entity SQL schema: migrate data.
 */
function node_update_8017(&$sandbox) {
  if (!isset($sandbox['progress'])) {
    // Initialize the batch status.
    $sandbox['progress'] = 0;
    $sandbox['max'] = db_query('SELECT COUNT(vid) FROM {node_revision}')->fetchField();
For faster browsing, not all history is shown. View entire blame