I noticed today that if node_delete is passed a 0 instead of a valid nid, the function just deletes the first node in the node table. (I deleted several pages of my site by accident to discover this.)
I think the problem might actually be in the node_load function, which node_delete calls.
http://api.drupal.org/api/function/node_load/5
if (is_numeric($param)) {
if ($cachable && isset($nodes[$param])) {
return is_object($nodes[$param]) ? drupal_clone($nodes[$param]) : $nodes[$param];
}
$cond = 'n.nid = %d';
$arguments[] = $param;
}
If I am guessing correctly, node_load will $nodes[0], which will be just the first element in the $nodes array. Not sure if this could be fixed by being explicit about the type of the array key, or excluding 0, etc.
Comments
Comment #1
xjm*will return $nodes[0]
(And therefore node_delete deletes that node.)
Comment #2
xjmAnother possible solution would be to modify node_delete such that it checks that $node->nid is the same as the $nid it was passed... I'm not sure if there's other implications for that.
Comment #3
dpearcefl commentedConsidering the time elapsed between now and the last comment plus the fact that D5 is no longer supported, I am closing this ticket.