node_delete

Versions
4.6
node_delete($edit)
4.7 – 7
node_delete($nid)

Delete a node.

▾ 4 functions call node_delete()

blogapi_blogger_delete_post in modules/blogapi/blogapi.module
Blogging API callback. Removes the specified blog node.
forum_taxonomy in modules/forum/forum.module
Implementation of hook_taxonomy().
node_delete_confirm_submit in modules/node/node.pages.inc
Execute node deletion
node_multiple_delete_confirm_submit in modules/node/node.admin.inc

Code

modules/node/node.module, line 958

<?php
function node_delete($nid) {

  $node = node_load($nid);

  if (node_access('delete', $node)) {
    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');

    // Clear the page and block caches.
    cache_clear_all();

    // Remove this node from the search index if needed.
    if (function_exists('search_wipe')) {
      search_wipe($node->nid, 'node');
    }
    watchdog('content', '@type: deleted %title.', array('@type' => $node->type, '%title' => $node->title));
    drupal_set_message(t('@type %title has been deleted.', array('@type' => node_get_types('name', $node), '%title' => $node->title)));
  }
}
?>

Note that node_delete() calls

Garrett Albright - Mon, 2009-11-09 21:07

Note that node_delete() calls node_load(), which keeps a cache of loaded nodes. That means it's possible to load a node with node_load() which should have been explicitly deleted with node_delete() earlier in the session! In other words, this works:

<?php
node_delete
($nid);
$node = node_load($nid);
?>

There are performance implications to this, and possibly security ones as well. See the node_load() documentation and its comments for information on how to clear node_load()'s cache. Also see this issue in Drupal's issue queue.

Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.