You are here

function antispam_content_delete in AntiSpam 6

Same name and namespace in other branches
  1. 7 antispam.module \antispam_content_delete()

Delete a node or a comment.

Parameters

string Content type; can be either 'node' or 'comment'.:

integer Content ID; can be either a nid or a cid.:

Return value

boolean TRUE if specified was there; FALSE otherwise.

2 calls to antispam_content_delete()
antispam_confirm_multiple_operation_submit in ./antispam.admin.inc
confirm_form callback; perform the actual operation against selected content.
antispam_cron_shutdown in ./antispam.cron.inc
Shutdown function executed at cron time.

File

./antispam.module, line 1692

Code

function antispam_content_delete($content_type, $content_id) {
  module_load_include('inc', 'comment', 'comment.admin');
  if ($content_type == 'node') {
    $node = antispam_content_load($content_type, $content_id);
    if ($node) {

      // Sadly, we cannot invoke node_delete() because it checks for the
      // user to have delete permission on nodes, and this function may
      // be invoked from a cron task, which is run as anonymous user, so
      // we have to hardcode the low level parts here.
      // Code based on node.module::node_delete().
      db_query('DELETE FROM {node} WHERE nid = %d', $node->nid);
      db_query('DELETE FROM {node_revisions} WHERE nid = %d', $node->nid);

      // Call the node-specific callback (if any):
      node_invoke($node, 'delete');
      node_invoke_nodeapi($node, 'delete');

      // Remove this node from the search index if needed.
      if (function_exists('search_wipe')) {
        search_wipe($node->nid, 'node');
      }

      // Record the event to watchdog.
      watchdog('content', '%type: deleted @title.', array(
        '%type' => t($node->type),
        '@title' => $node->title,
      ));
      return TRUE;
    }
  }
  else {
    if ($content_type == 'comment') {
      $comment = antispam_content_load($content_type, $content_id);
      if ($comment) {
        _comment_delete_thread($comment);
        _comment_update_node_statistics($comment->cid);
        return TRUE;
      }
    }
  }
  return FALSE;
}