You are here

function comment_delete_keep_replies in Comment Delete 7

Removes comment while keeping all replies.

Parameters

object $comment: Fully loaded comment object.

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

File

./comment_delete.module, line 249
comment_delete.module

Code

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

  // Retrieve first-level comment replies count.
  $replies = db_select('comment', 'c')
    ->fields('c', array(
    'cid',
  ))
    ->condition('c.pid', $comment->cid, '=')
    ->countQuery()
    ->execute()
    ->fetchField();

  // Remove subject/body when replies exist.
  if ($replies > 0) {
    $comment->subject = '';
    $comment->comment_body[$comment->language][0]['value'] = '';
    comment_save($comment);
  }
  else {
    if (!$soft) {
      comment_delete($comment->cid);
    }
    else {
      comment_delete_soft_remove($comment);
    }
  }
}