Using this method, you can easily mass delete nodes from your site by content type. Also, feel free to modify the SQL for your own purposes.
To use this code, you will need a custom module. As a best practice, I always create a site module for instances just like this. Within your module folder, create a 'module_name.install' file and place the following code within it.
<?php
// $Id$
/**
* @file
* Handles installing, uninstalling, and updating the site.
*/
function MODULE_update_1() {
//set the node type
$nodetype = "twitter_item";
// see d.o issue #666826
if (module_exists('luceneapi')) {
luceneapi_init()
}
// See if we are being called for the first time
if (!isset($_SESSION['MODULE_update_1_nid'])) {
// These variables keep track of our progress
$_SESSION['MODULE_update_1_nid'] = 0;
$_SESSION['MODULE_update_1_max'] = db_result(db_query("SELECT MAX(nid) FROM {node} WHERE type='%s'", $nodetype));
}
// Fetch the next 20 nodes
$result = db_query_range('SELECT nid FROM {node} WHERE nid > %d AND type = "%s" ORDER BY nid ASC', $_SESSION['MODULE_update_1_nid'], $nodetype, 0, 20);
while ($node = db_fetch_object($result)) {
node_delete($node->nid);
$_SESSION['MODULE_update_1_nid'] = $node->nid;
}
// See if we are done
if ($_SESSION['MODULE_update_1_nid'] < $_SESSION['MODULE_update_1_max']) {
// Not done yet. Return the progress.
return array('#finished' => $_SESSION['MODULE_update_1_nid'] / $_SESSION['MODULE_update_1_max']);
}
else {
// Done. Clean up and indicate we're finished.
unset($_SESSION['MODULE_update_1_nid']);
unset($_SESSION['MODULE_update_1_max']);
return array('#finished' => 1);
}
}
Now, replace all occurrences of 'MODULE' with the name of your module, as well as defining your content type. Save your file, run update.php, sit back and relax. This method will work for literally thousands of nodes, and can be modified for any use case.
Resources
http://drupal.org/node/51220
