You are here

function comment_delete_move_replies in Comment Delete 7

Same name and namespace in other branches
  1. 6 comment_delete.module \comment_delete_move_replies()

Moves comment replies up one thread.

Parameters

object $comment: Fully loaded comment object.

1 call to comment_delete_move_replies()
comment_delete_options_form_submit in ./comment_delete.module
Submission handler for comment deletion form.

File

./comment_delete.module, line 283
comment_delete.module

Code

function comment_delete_move_replies($comment) {
  $soft = variable_get('comment_delete_soft', 0);

  // Retrieve all first-level comment replies to be updated.
  $replies = db_select('comment', 'c')
    ->fields('c', array(
    'cid',
  ))
    ->condition('c.pid', $comment->cid, '=')
    ->execute();

  // Update parent comment target ID.
  foreach ($replies as $reply) {
    $reply_comment = comment_load($reply->cid);
    $reply_comment->pid = $comment->pid;
    comment_save($reply_comment);
  }

  // Delete the parent comment record.
  if (!$soft) {
    comment_delete($comment->cid);
  }
  else {
    comment_delete_soft_remove($comment);
  }

  // Re-thread comments attached to node.
  comment_delete_threading($comment->nid);
}