Community Documentation

comment_update_7001

7 comment.install comment_update_7001()

Change comment status from published being 0 to being 1

File

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

Code

<?php
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();
  }
}
?>
Login or register to post comments