I have a lot of nodes on my test site... about 40,000. I want to get rid of almost all of a certain kind of these in bulk. For example, I added 38,000 content type "article" nodes on June 14th I want to remove.

I understand there are many ways to do this, but what is the easiest? I've installed many plugins which supposedly do this, but I haven't been able to figure out how to use them to do what i need. I guess drush is an option, but I'm not sure where to run those command either.

What's the best way, step by step, to remove multiples nodes?

Thanks!

Comments

sprite’s picture

First backup your work ...

As you consider your options, create a backup website and test out options there before deleting anything from your production website.

spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...

pixelsweatshop’s picture

You can use Views bulk operations to build out a view of what you want to bulk delete.

A few years back I built a module that modifies the admin/content view with a bunch of extras (similar to the admin views module). One of the exposed filters is "Date posted" (you can also choose a date range). You can then filter for the ones created on June 14 and the bulk delete them.

https://www.drupal.org/project/admin_frosting

I just tested and the module works fine still. So you can use vbo or give Admin Frosting a go.

Jaypan’s picture

I'd create a custom drush command, that takes a date as an input and then deletes all nodes from that date.

First, in your custom module, add a [MODULENAME].drush.inc file.
Then, implement hook_drush_command()

/**
 * Implements hook_drush_command().
 */
function hook_drush_command() {

  $items['delete-nodes-for-day'] = array
  (
    'description' => 'Deletes nodes created on the given date',
    'aliases' => array('dnfd'),
    'arguments' => array
    (
       'date' => 'The date in YYYY-mm-dd format',
     ),
    'examples' => array
    (
      'dnfd 2017-06-14',
    ),
  );

  return $items;
}

The callback for this function will be in the format drush_[modulename]_[command] where the hyphens in the command are changed to underscores:

function drush_[MODULENAME]_delete_nodes_for_day($date)
{
  $date_parts = explode('-', $date);
  // Get midnight of the given day
  $start = mktime(0, 0, 0, $date_parts[1], $date_parts[2], $date_parts[0]);
  // Get 23:59:59 of the given day
  $end = mktime (23, 59, 59, $date_parts[1], $date_parts[2], $date_parts[0]);

  // Get all NIDs for the given day
  $nids = db_query('SELECT nid FROM {node} WHERE created >= :start AND created <= :end', array(':start' => $start, ':end' => $end))->fetchCol();

  // Loop through the NIDs and delete individually
  foreach($nids as $nid)
  {
    $node = node_load($nid);
    if($node)
    {
      node_delete($node);
    }
  }
}

Then you can call this using dnfd 2017-06-14.

Make sure you back up your database first in case something goes wrong!

Utkarsh Harshit’s picture

Hi,
Use Bulk delete module....

It is an abandoned module. See for alternatives:

  1. Views Bulk Operations
  2. Delete All