| 7 node.module | node_delete_multiple($nids) |
| 8 node.module | node_delete_multiple($nids) |
Delete multiple nodes.
Parameters
$nids: An array of node IDs.
3 calls to node_delete_multiple()
File
- modules/
node/ node.module, line 1191 - The core that allows content to be submitted to the site. Modules and scripts may programmatically submit nodes using the usual form API pattern.
Code
function node_delete_multiple($nids) {
$transaction = db_transaction();
if (!empty($nids)) {
$nodes = node_load_multiple($nids, array());
try {
foreach ($nodes as $nid => $node) {
// Call the node-specific callback (if any):
node_invoke($node, 'delete');
module_invoke_all('node_delete', $node);
module_invoke_all('entity_delete', $node, 'node');
field_attach_delete('node', $node);
// Remove this node from the search index if needed.
// This code is implemented in node module rather than in search module,
// because node module is implementing search module's API, not the other
// way around.
if (module_exists('search')) {
search_reindex($nid, 'node');
}
}
// Delete after calling hooks so that they can query node tables as needed.
db_delete('node')
->condition('nid', $nids, 'IN')
->execute();
db_delete('node_revision')
->condition('nid', $nids, 'IN')
->execute();
db_delete('history')
->condition('nid', $nids, 'IN')
->execute();
db_delete('node_access')
->condition('nid', $nids, 'IN')
->execute();
}
catch (Exception $e) {
$transaction->rollback();
watchdog_exception('node', $e);
throw $e;
}
// Clear the page and block and node_load_multiple caches.
entity_get_controller('node')->resetCache();
}
}
Login or register to post comments
Comments
Argument length limit
The number of nodes that can be loaded into memory in a single query is limited by the PDO layer, the database driver, configuration details, and of course, available memory. Passing too large an argument array to this function can result in the cryptic error message General error: 1 too many SQL variables.
A documentation bug has been posted to note the limited argument length.