function _content_profile_node_delete in Content Profile 6
The original node_delete() function uses node_load() to get the $node object. Unfortunately, when a hook_user('delete') is called, node_load() doesn't work anymore because the user has already been deleted, and node_load() still expects the user to exist in the {user} table.
So this is a modified copy of node_delete() that deletes a node without calling node_load(), taking the full $node object (as retrieved by a simple "SELECT * FROM {node}" query) instead of just the $nid.
1 call to _content_profile_node_delete()
- content_profile_user in ./
content_profile.module - Implementation of hook_user().
File
- ./
content_profile.module, line 328
Code
function _content_profile_node_delete($node) {
// Copied over from node_load(), so that node_invoke('delete') gets
// the fully extended node object, like modules would expect:
if ($node->nid) {
// Call the node specific callback (if any) and piggy-back the
// results to the node or overwrite some values.
if ($extra = node_invoke($node, 'load')) {
foreach ($extra as $key => $value) {
$node->{$key} = $value;
}
}
if ($extra = node_invoke_nodeapi($node, 'load')) {
foreach ($extra as $key => $value) {
$node->{$key} = $value;
}
}
}
// Copied over from 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');
// Clear the cache so an anonymous poster can see the node being deleted.
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,
)));
}