comment.install 23.3 KB
Newer Older
1 2
<?php

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

8
use Drupal\Core\Language\Language;
9
use Drupal\comment\Plugin\Field\FieldType\CommentItem;
10 11
use Drupal\field\Entity\Field;

12
/**
13
 * Implements hook_uninstall().
14 15
 */
function comment_uninstall() {
16
  // Remove the comment fields.
17
  $fields = entity_load_multiple_by_properties('field_entity', array('type' => 'comment'));
18 19 20
  foreach ($fields as $field) {
    entity_invoke_bundle_hook('delete', 'comment', $field->entity_type . '__' . $field->name);
    $field->delete();
21
  }
22

23
  // Remove state setting.
24
  \Drupal::state()->delete('comment.node_comment_statistics_scale');
25 26
}

27
/**
28
 * Implements hook_install().
29
 */
30
function comment_install() {
31 32 33
  // By default, maintain entity statistics for comments.
  // @see \Drupal\comment\CommentStorageController::updateEntityStatistics().
  \Drupal::state()->set('comment.maintain_entity_statistics', TRUE);
34 35
}

36
/**
37
 * Implements hook_schema().
38 39
 */
function comment_schema() {
40
  $schema['comment'] = array(
41
    'description' => 'Stores comments and associated data.',
42
    'fields' => array(
43 44 45
      'cid' => array(
        'type' => 'serial',
        'not null' => TRUE,
46
        'description' => 'Primary Key: Unique comment ID.',
47
      ),
48 49 50 51 52 53
      'uuid' => array(
        'description' => 'Unique Key: Universally unique identifier for this entity.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => FALSE,
      ),
54 55 56 57
      'pid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
58
        'description' => 'The {comment}.cid to which this comment is a reply. If set to 0, this comment is not a reply to an existing comment.',
59
      ),
60
      'entity_id' => array(
61
        'type' => 'int',
62
        'unsigned' => TRUE,
63 64
        'not null' => TRUE,
        'default' => 0,
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
        'description' => 'The entity_id of the entity to which this comment is a reply.',
      ),
      'entity_type' => array(
        'type' => 'varchar',
        'not null' => TRUE,
        'default' => 'node',
        'length' => 255,
        'description' => 'The entity_type of the entity to which this comment is a reply.',
      ),
      'field_id' => array(
        'type' => 'varchar',
        'not null' => TRUE,
        'default' => 'node.comment',
        'length' => 255,
        'description' => 'The field_id of the field that was used to add this comment.',
80 81 82
      ),
      'uid' => array(
        'type' => 'int',
83
        'unsigned' => TRUE,
84 85
        'not null' => TRUE,
        'default' => 0,
86
        'description' => 'The {users}.uid who authored the comment. If set to 0, this comment was created by an anonymous user.',
87 88 89 90 91 92
      ),
      'subject' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
93
        'description' => 'The comment title.',
94 95 96 97 98 99
      ),
      'hostname' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
100
        'description' => "The author's host name.",
101
      ),
102 103 104 105 106 107 108
      'created' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The time that the comment was created, as a Unix timestamp.',
      ),
      'changed' => array(
109 110 111
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
112
        'description' => 'The time that the comment was last edited, as a Unix timestamp.',
113 114 115 116 117
      ),
      'status' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
118
        'default' => 1,
119
        'size' => 'tiny',
120
        'description' => 'The published status of a comment. (0 = Not Published, 1 = Published)',
121 122 123 124 125
      ),
      'thread' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
126
        'description' => "The alphadecimal representation of the comment's place in a thread, consisting of a base 36 string prefixed by an integer indicating its length.",
127 128 129 130 131
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 60,
        'not null' => FALSE,
132
        'description' => "The comment author's name. Uses {users}.name if the user is logged in, otherwise uses the value typed into the comment form.",
133 134 135 136 137
      ),
      'mail' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => FALSE,
138
        'description' => "The comment author's e-mail address from the comment form, if user is anonymous, and the 'Anonymous users may/must leave their contact information' setting is turned on.",
139 140 141 142 143
      ),
      'homepage' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
144
        'description' => "The comment author's home page address from the comment form, if user is anonymous, and the 'Anonymous users may/must leave their contact information' setting is turned on.",
145
      ),
146
      'langcode' => array(
147
        'description' => 'The {language}.langcode of this comment.',
148 149 150 151 152
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
      ),
153 154
    ),
    'indexes' => array(
155
      'comment_status_pid' => array('pid', 'status'),
156 157 158 159 160 161 162 163 164
      'comment_num_new' => array(
        'entity_id',
        array('entity_type', 32),
        array('field_id', 32),
        'status',
        'created',
        'cid',
        'thread',
      ),
165
      'comment_uid' => array('uid'),
166 167 168 169 170 171
      'comment_entity_langcode' => array(
        'entity_id',
        array('entity_type', 32),
        array('field_id', 32),
        'langcode',
      ),
172
      'comment_created' => array('created'),
173 174
    ),
    'primary key' => array('cid'),
175 176 177
    'unique keys' => array(
      'uuid' => array('uuid'),
    ),
178
    'foreign keys' => array(
179 180 181 182
      'comment_author' => array(
        'table' => 'users',
        'columns' => array('uid' => 'uid'),
      ),
183
    ),
184 185
  );

186 187
  $schema['comment_entity_statistics'] = array(
    'description' => 'Maintains statistics of entity and comments posts to show "new" and "updated" flags.',
188
    'fields' => array(
189
      'entity_id' => array(
190 191 192 193
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
        'description' => 'The entity_id of the entity for which the statistics are compiled.',
      ),
      'entity_type' => array(
        'type' => 'varchar',
        'not null' => TRUE,
        'default' => 'node',
        'length' => 255,
        'description' => 'The entity_type of the entity to which this comment is a reply.',
      ),
      'field_id' => array(
        'type' => 'varchar',
        'not null' => TRUE,
        'default' => 'node__comment',
        'length' => 255,
        'description' => 'The field_id of the field that was used to add this comment.',
209
      ),
210 211 212 213 214 215
      'cid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The {comment}.cid of the last comment.',
      ),
216 217 218 219
      'last_comment_timestamp' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
220
        'description' => 'The Unix timestamp of the last comment that was posted within this node, from {comment}.changed.',
221 222 223 224 225
      ),
      'last_comment_name' => array(
        'type' => 'varchar',
        'length' => 60,
        'not null' => FALSE,
226
        'description' => 'The name of the latest author to post a comment on this node, from {comment}.name.',
227 228 229
      ),
      'last_comment_uid' => array(
        'type' => 'int',
230
        'unsigned' => TRUE,
231 232
        'not null' => TRUE,
        'default' => 0,
233
        'description' => 'The user ID of the latest author to post a comment on this node, from {comment}.uid.',
234 235 236 237 238 239
      ),
      'comment_count' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
240
        'description' => 'The total number of comments on this entity.',
241 242
      ),
    ),
243
    'primary key' => array('entity_id', array('entity_type', 32), array('field_id', 32)),
244
    'indexes' => array(
245
      'last_comment_timestamp' => array('last_comment_timestamp'),
246
      'comment_count' => array('comment_count'),
247
      'last_comment_uid' => array('last_comment_uid'),
248
    ),
249
    'foreign keys' => array(
250 251 252 253 254 255
      'last_comment_author' => array(
        'table' => 'users',
        'columns' => array(
          'last_comment_uid' => 'uid',
        ),
      ),
256
    ),
257 258 259
  );

  return $schema;
260
}
261 262 263 264 265 266

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

267 268 269 270 271 272 273 274 275 276
/**
 * Implements hook_update_dependencies().
 */
function comment_update_dependencies() {
  // Node comment status cannot be turned into fields until after the fields and
  // instances are converted to ConfigEntities.
  $dependencies['comment'][8006]['field'] = 8003;
  return $dependencies;
}

277 278 279 280
/**
 * Renames {comment}.language to {comment}.langcode.
 */
function comment_update_8000() {
281
  db_drop_index('comment', 'comment_nid_language');
282 283 284 285 286 287 288 289 290 291 292
  $langcode_spec = array(
    'type' => 'varchar',
    'length' => 12,
    'not null' => TRUE,
    'default' => '',
    'description' => "Language code, e.g. 'de' or 'en-US'.",
  );
  db_change_field('comment', 'language', 'langcode', $langcode_spec);
  db_add_index('comment', 'comment_nid_langcode', array('nid', 'langcode'));
}

293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
/**
 * Create a UUID column for comments.
 */
function comment_update_8001() {
  $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('comment', 'uuid')) {
    db_change_field('comment', 'uuid', 'uuid', $spec, $keys);
  }
  else {
    db_add_field('comment', 'uuid', $spec, $keys);
  }
}

317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
/**
 * Make *id fields unsigned.
 */
function comment_update_8002() {
  db_drop_index('comment', 'comment_num_new');
  db_drop_index('comment', 'comment_nid_langcode');
  db_change_field('comment', 'nid', 'nid',
    array(
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
      'description' => 'The {node}.nid to which this comment is a reply.',
    ),
    array('indexes' => array(
      'comment_num_new' => array('nid', 'status', 'created', 'cid', 'thread'),
      'comment_nid_langcode' => array('nid', 'langcode'),
    ))
  );
  db_drop_index('comment', 'comment_uid');
  db_change_field('comment', 'uid', 'uid',
    array(
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
      'description' => 'The {users}.uid who authored the comment. If set to 0, this comment was created by an anonymous user.',
    ),
    array('indexes' => array(
      'comment_uid' => array('uid'),
    ))
  );

  db_drop_index('node_comment_statistics', 'last_comment_uid');
  db_change_field('node_comment_statistics', 'last_comment_uid', 'last_comment_uid',
    array(
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
      'description' => 'The user ID of the latest author to post a comment on this node, from {comment}.uid.',
    ),
    array('indexes' => array(
      'last_comment_uid' => array('last_comment_uid'),
    ))
  );
}

365
/**
366
 * Generate a UUID for all comments.
367 368 369 370 371 372 373 374 375 376 377 378 379 380
 */
function comment_update_8003(&$sandbox) {
  if (!isset($sandbox['progress'])) {
    $sandbox['progress'] = 0;
    $sandbox['last'] = 0;
    $sandbox['max'] = db_query('SELECT COUNT(cid) FROM {comment} WHERE uuid IS NULL')->fetchField();
  }

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

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

381 382 383 384 385 386
/**
 * Convert variables to state.
 */
function comment_update_8004() {
  update_variables_to_state(array(
    'node_cron_comments_scale' => 'comment.node_comment_statistics_scale',
387
    'comment_maintain_node_statistics' => 'comment.maintain_entity_statistics',
388 389 390
  ));
}

391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 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 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 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703
/**
 * Update the {comment_node_statistics} and {comment} tables to new structure.
 */
function comment_update_8005(&$sandbox) {
  // Drop old indexes.
  if (db_index_exists('comment', 'comment_node')) {
    // Drop the comment_node foreign key.
    db_drop_index('comment', 'comment_node');
  }
  db_drop_index('comment', 'comment_num_new');
  db_drop_index('comment', 'comment_nid_langcode');

  // Add the entity_type and field id columns to comment.
  db_add_field('comment', 'entity_type', array(
    'type' => 'varchar',
    'not null' => TRUE,
    'default' => 'node',
    'length' => 255,
    'description' => 'The entity_type of the entity to which this comment is a reply.',
  ));
  db_add_field('comment', 'field_id', array(
    'type' => 'varchar',
    'not null' => TRUE,
    'default' => 'node__comment',
    'length' => 255,
    'description' => 'The field_id of the field that was used to add this comment.',
  ));
  // Rename the nid column to entity_id.
  db_change_field('comment', 'nid', 'entity_id', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
    'description' => 'The entity_id of the entity to which this comment is a reply.',
  ));
  db_add_index('comment', 'comment_num_new', array(
    'entity_id',
    array('entity_type', 32),
    array('field_id', 32),
    'status',
    'created',
    'cid',
    'thread'
  ));
  // Add the comment_entity_langcode index.
  db_add_index('comment', 'comment_entity_langcode', array(
    'entity_id',
    array('entity_type', 32),
    array('field_id', 32),
    'langcode',
  ));

  // We need to drop all indexes to make sure their constrains named properly.
  db_drop_primary_key('node_comment_statistics');
  if (db_index_exists('node_comment_statistics', 'statistics_node')) {
    // Drop the statistics_node foreign key.
    db_drop_index('node_comment_statistics', 'statistics_node');
  }
  db_drop_index('node_comment_statistics', 'node_comment_timestamp');
  db_drop_index('node_comment_statistics', 'comment_count');
  db_drop_index('node_comment_statistics', 'last_comment_uid');

  // Rename {node_comment_statistics} to {comment_entity_statistics}.
  db_rename_table('node_comment_statistics', 'comment_entity_statistics');

  // Add the entity_type and field id columns to comment_entity_statistics.
  db_add_field('comment_entity_statistics', 'entity_type', array(
    'type' => 'varchar',
    'not null' => TRUE,
    'default' => 'node',
    'length' => 255,
    'description' => 'The entity_type of the entity to which this comment is a reply.',
  ));
  db_add_field('comment_entity_statistics', 'field_id', array(
    'type' => 'varchar',
    'not null' => TRUE,
    'default' => 'node__comment',
    'length' => 255,
    'description' => 'The field_id of the field that was used to add this comment.',
  ));
  // Rename the nid column in entity_comment_statistics to entity_id.
  db_change_field('comment_entity_statistics', 'nid', 'entity_id', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
    'description' => 'The entity_id of the entity to which this comment is a reply.',
  ));

  // Add indexes.
  db_add_primary_key('comment_entity_statistics', array('entity_id', array('entity_type', 32), array('field_id',32)));
  db_add_index('comment_entity_statistics', 'last_comment_timestamp', array('last_comment_timestamp'));
  db_add_index('comment_entity_statistics', 'comment_count', array('comment_count'));
  db_add_index('comment_entity_statistics', 'last_comment_uid', array('last_comment_uid'));
}

/**
 * Adds comment fields for all node types.
 *
 * Field instance settings "default_mode", "per_page" and "form_location" are
 * preserved to allow migrate contrib modules.
 */
function comment_update_8006(&$sandbox) {
  // Entity module update functions are needed to update components of node
  // entity display and form display for new comment fields.
  module_load_install('entity');
  // Loop over defined node_types.
  $node_types = array_keys(_update_7000_node_get_types());
  foreach ($node_types as $node_type) {
    // COMMENT_OPEN
    $default_value = update_variable_get('comment_' . $node_type, 2);
    // Add a default comment field for existing node comments.
    $field_name = 'comment_' . $node_type;
    $field = array(
      // We need one per content type to match the existing comment bundles.
      'id' => 'node.' . $field_name,
      'type' => 'comment',
      'module' => 'comment',
      'name' => $field_name,
      'entity_type' => 'node',
    );
    // Make sure field doesn't already exist.
    $index = 0;

    // @todo Refactor once https://drupal.org/node/1856972 lands.
    while (!\Drupal::config('field.field.node.' . $field['name'])->isNew()) {
      // Append a numeric index.
      $field['id'] = 'node.' . $field_name . '_' . $index;
      $field['name'] = $field_name . '_' . $index;
      // Increment index.
      $index++;
    }
    $field_object = new Field($field);
    $field['schema'] = CommentItem::schema($field_object);
    _update_8003_field_create_field($field);

    // @todo Refactor once https://drupal.org/node/1856972 lands.
    if (\Drupal::config("field.instance.node.$node_type." . $field['name'])->isNew()) {
      // Add the comment field, setting the instance settings to match those for
      // the given node_type.
      $instance_settings = array(
        // COMMENT_MODE_THREADED
        'default_mode' => update_variable_get('comment_default_mode_' . $node_type, 1),
        'per_page' => update_variable_get('comment_default_per_page_' . $node_type, 50),
        // COMMENT_FORM_BELOW
        'form_location' => update_variable_get('comment_form_location_' . $node_type, 1),
        // COMMENT_ANONYMOUS_MAYNOT_CONTACT
        'anonymous' => update_variable_get('comment_anonymous_' . $node_type, 0),
        'subject' => update_variable_get('comment_subject_field_' . $node_type, 1),
        // DRUPAL_OPTIONAL
        'preview' => update_variable_get('comment_preview_' . $node_type, 1),
      );
      $instance = array(
        'id' => "node.$node_type." . $field['name'],
        'entity_type' => 'node',
        'bundle' => $node_type,
        'default_value' => array(array('status' => $default_value)),
        'deleted' => '0',
        'description' => '',
        'label' => 'Comment settings',
        'required' => TRUE,
        'settings' => $instance_settings,
      );
      _update_8003_field_create_instance($field, $instance);
    }

    // Prepare defaults for the default and full view modes.
    $display_options_default = array(
      'label' => 'hidden',
      'type' => 'comment_default',
      'settings' => array(),
      'weight' => 20,
    );

    // Assign display settings for the 'default' and 'full' view modes.
    $display = _update_8000_entity_get_display('node', $node_type, 'default');
    $display->set('content.' . $field['name'], $display_options_default)
      ->save();

    $display = _update_8000_entity_get_display('node', $node_type, 'full');
    $display->set('content.' . $field['name'], $display_options_default)
      ->save();

    // Assign widget settings for the 'default' form mode.
    $display_options_default = array(
      'type' => 'comment_default',
      'settings' => array(),
      'weight' => 20,
    );
    $display = _update_8000_entity_get_form_display('node', $node_type, 'default');
    $display->set('content.' . $field['name'], $display_options_default)
      ->save();

    // Clean up old variables.
    update_variable_del('comment_' . $node_type);
    update_variable_del('comment_default_mode_' . $node_type);
    update_variable_del('comment_default_per_page_' . $node_type);
    update_variable_del('comment_anonymous_' . $node_type);
    update_variable_del('comment_subject_field_' . $node_type);
    update_variable_del('comment_form_location_' . $node_type);
    update_variable_del('comment_preview_' . $node_type);
  }
}

/**
 * Update existing comment values from node table to field data.
 */
function comment_update_8007(&$sandbox) {

  $types = array_keys(_update_7000_node_get_types());
   // Load each node type in batch and initialize field values for comment field.
  if (!isset($sandbox['progress'])) {
    $sandbox['progress'] = 0;
    $sandbox['current_nid'] = 0;
    // We track all node types here.
    $sandbox['node_types'] = $types;
    // We start with this node type.
    $sandbox['node_type'] = array_shift($sandbox['node_types']);
    $sandbox['#finished'] = 1;
    $sandbox['max'] = db_query('SELECT COUNT(nid) FROM {node}')->fetchField();
  }

  // Set the initial values of comment fields for existing nodes. Note that
  // contrib modules will need to handle the upgrade path on their own, as
  // they are disabled during core upgrade.

  // Node table will always exist up until here because in 7.x comment
  // depends on node.
  $nodes = db_select('node', 'n')
    ->fields('n', array('nid', 'comment', 'vid', 'langcode'))
    ->condition('type', $sandbox['node_type'])
    ->condition('nid', $sandbox['current_nid'], '>')
    ->range(0, 50)
    ->orderBy('nid', 'ASC')
    ->execute()
    ->fetchAllAssoc('nid');

  if (count($nodes) > 0) {
    $insert = db_insert('node__comment_' . $sandbox['node_type'])
      ->fields(array(
        'bundle',
        'entity_id',
        'revision_id',
        'langcode',
        'delta',
        'comment_' . $sandbox['node_type'] . '_status',
      ));
    $revision = db_insert('node_revision__comment_' . $sandbox['node_type'])
      ->fields(array(
        'bundle',
        'entity_id',
        'revision_id',
        'langcode',
        'delta',
        'comment_' . $sandbox['node_type'] . '_status',
      ));

    // Update the field name to match the node type.
    db_update('comment')
      ->fields(array(
        'field_id' => 'node__comment_' . $sandbox['node_type'],
      ))
      ->condition('entity_id', array_keys($nodes))
      ->execute();
    foreach ($nodes as $nid => $node) {
      $insert->values(array(
        'bundle' => $sandbox['node_type'],
        'entity_id' => $nid,
        'revision_id' => $node->vid,
        'langcode' => Language::LANGCODE_NOT_SPECIFIED,
        'delta' => 0,
        'comment_' . $sandbox['node_type'] . '_status' => $node->comment,
      ));
      $revision->values(array(
        'bundle' => $sandbox['node_type'],
        'entity_id' => $nid,
        'revision_id' => $node->vid,
        'langcode' => Language::LANGCODE_NOT_SPECIFIED,
        'delta' => 0,
        'comment_' . $sandbox['node_type'] . '_status' => $node->comment,
      ));
      $sandbox['progress']++;
      $sandbox['current_nid'] = $nid;
    }
    $insert->execute();
    $revision->execute();
    // Populate the field name to match the node type.
    db_update('comment_entity_statistics')
      ->fields(array(
        'field_id' => 'node__comment_' . $sandbox['node_type'],
      ))
      ->condition('entity_id', array_keys($nodes))
      ->execute();
  }
  else {
    // Move to the next node type.
    $sandbox['node_type'] = array_shift($sandbox['node_types']);
    // Reset the current nid pointer.
    $sandbox['current_nid'] = 0;
  }
  $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
}

/**
 * Removes the existing fields.
 *
 * Data was migrated in comment_update_8007().
 */
function comment_update_8008(&$sandbox) {
  // Remove the {node}.comment field.
  db_drop_field('node', 'comment');
  // Remove the {node_revision}.comment field.
  db_drop_field('node_revision', 'comment');
}

704
/**
705
 * @} End of "addtogroup updates-7.x-to-8.x".
706 707
 * The next series of updates should start at 9000.
 */