function comment_update_7001

Change comment status from published being 0 to being 1

Related topics

File

modules/comment/comment.install, line 141

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();
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.