You are here

function comment_delete_form_submit in Comment Delete 6

Delete the comment and manage the replies using the appropiate action.

File

./comment_delete.module, line 137

Code

function comment_delete_form_submit($form, &$form_state) {
  include_once drupal_get_path('module', 'comment') . '/comment.admin.inc';
  $comment = _comment_load($form_state['values']['cid']);

  // Delete the comment and all of it's replies.
  if (!$form_state['values']['replies']) {
    _comment_delete_thread($comment);
    _comment_update_node_statistics($comment->nid);
    drupal_set_message(t('The comment and all its replies have been deleted.'));
  }
  elseif ($form_state['values']['replies'] == 1) {
    comment_delete_move_replies($comment);
    _comment_delete_thread($comment);
    _comment_update_node_statistics($comment->nid);
    drupal_set_message(t("The comment has been deleted and it's replies have been moved up one level."));
  }
  elseif ($form_state['values']['replies'] == 2) {
    if (comment_num_replies($comment->cid)) {
      db_query("UPDATE {comments} SET subject = '', comment = '%s' WHERE cid = %d", t('This comment has been deleted.'), $comment->cid);
      drupal_set_message(t('The comment subject/body has been deleted, all replies will remain.'));
    }
    else {
      _comment_delete_thread($comment);
      _comment_update_node_statistics($comment->nid);
      drupal_set_message(t('The comment has been deleted.'));
    }
  }
  cache_clear_all();
  $form_state['redirect'] = "node/{$comment->nid}";
}