Utility: Delete all nodes in a site

AttachmentSize
Binary Data deleteall.4.6.module909 bytes
Binary Data deleteall.4.7.module878 bytes

Here is a module that can come in handy in certain cases.

Say you have a site and want to delete all content in it.

Reasons are:

  • This is a test site that the client was using for a period of time, and they must clean it up before starting with real data.
  • You are testing something that creates a lot of nodes (e.g. aggregator), and want to do it over and over again.
  • You created a site in the past and want to replicate it again, but with new content.

The traditional way of doing this is to go into administer -> content then select all the nodes and delete them. This works if you have a handful of nodes only. If you have hundreds or thousands of nodes, then it is not a practical solution.

Another option is to directly delete the nodes from the node table in the database. This does not work properly, since there are also comments, and many tables for add on modules that needs to be cleaned.

So, my solution was to write this small module to delete all content programmatically.

I am attaching two files, one for 4.6 and the other for 4.7.

Instructions

Download the module for your Drupal version below, copy them to your modules directory, enable the module, then visit http://example.com/admin/node/deleteall

Update

The module is now updated for Drupal 5.x, and lives in the Drupal repository. It also provides an option to delete all users. See the Delete all project.

Contents: 

Comments

massdelete

I think the massdelete.module does this already.

Cannot download

Thanks for this module, great idea!

But I can't download the attachements, I get a 403 error message (Forbidden).

HI, This sounds like a great

HI,
This sounds like a great module; how do in activate it? i created the file and put in modules and activated it but cant find anyplace where i can have it delete all nodes.

thnx

Hi, thnx for the

Hi,
thnx for the instructions; when i activate delete in my modules as an administrator and than go to the path for node/deletall, i get the content page where i can mark nodes and delete one by one [this is the same as just going to the content page in admin]; am i missing a step here to get your script to work?

thnx

Not enabled

It means that this module is not properly enabled then, or the menu cache needs to be refreshed.

Enable it, then go and visit /admin/menu to clear the menu cache, then go and visit /admin/node/deleteall.
--
2bits -- Drupal consulting