Created
August 7, 2013 12:35
-
-
Save sumeetpareek/6173667 to your computer and use it in GitHub Desktop.
Drush script to read NIDs from a CSV file and bulk delete the nodes using node_delete()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
This is a 'drush php-script' alternative to the SITE.com/devel/php approach | |
to this answer - http://drupal.stackexchange.com/a/81221/4450 | |
A short description of drush php-script below | |
$ drush help php-script | |
Runs the given php script(s) after a full Drupal bootstrap. | |
Example of how to run this script | |
drush php-script /path/to/this/file/node_bulk_delete_by_nids.drush.php /path/to/csv_file_with_nids.csv | |
^ Make sure to run this command from within the desired drupal site's directory tree | |
*/ | |
$path_to_file = drush_shift(); | |
$nids = file_get_contents($path_to_file); | |
$nids = explode(",", $nids); // This will depend on how your nids are delimited. Could be line break "\n" | |
foreach ($nids as $n) { | |
node_delete($n); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment