function comment_update_7001

7.x comment.install comment_update_7001()

Change comment status from published being 0 to being 1

Related topics

File

drupal-7.x/modules/comment/comment.install, line 144
Install, update and uninstall functions for the comment module.

Code

function comment_update_7001() {
  // Choose a temporary status value different from the existing status values.
  $tmp_status = db_query('SELECT MAX(status) FROM {comments}')->fetchField() + 1;

  $changes = array(
    0 => $tmp_status,
    1 => 0,
    $tmp_status => 1,
  );

  foreach ($changes as $old => $new) {
    db_update('comments')
      ->fields(array('status' => $new))
      ->condition('status', $old)
      ->execute();
  }
}