You are here

function _user_delete_comment_delete_thread in User Delete 6.2

Perform the actual deletion of a comment and all its replies.

Parameters

$comment: An associative array describing the comment to be deleted.

1 call to _user_delete_comment_delete_thread()
_user_delete_comment_mass_delete_helper in ./user_delete.module
comment Mass Update - helper function.

File

./user_delete.module, line 1068
Provide account cancellation methods and API to provide the same functionalty as Drupal 7 for cancelling accounts.

Code

function _user_delete_comment_delete_thread($comment) {
  if (!is_object($comment) || !is_numeric($comment->cid)) {
    watchdog('content', 'Cannot delete non-existent comment.', array(), WATCHDOG_WARNING);
    return;
  }

  // Delete the comment:
  db_query('DELETE FROM {comments} WHERE cid = %d', $comment->cid);
  watchdog('content', 'Comment: deleted %subject.', array(
    '%subject' => $comment->subject,
  ));
  foreach (module_implements('comment') as $name) {
    $function = $name . '_comment';
    $result = $function($comment, 'delete');
    if (isset($result) && is_array($result)) {
      $return = array_merge($return, $result);
    }
    elseif (isset($result)) {
      $return[] = $result;
    }
  }

  // Delete the comment's replies
  $result = db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid WHERE pid = %d', $comment->cid);
  while ($comment = db_fetch_object($result)) {
    $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
    _user_delete_comment_delete_thread($comment);
  }
}