Skip to content

Instantly share code, notes, and snippets.

@sarahg
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sarahg/993b97d6733003814fda to your computer and use it in GitHub Desktop.
Save sarahg/993b97d6733003814fda to your computer and use it in GitHub Desktop.
Delete all nodes on a Drupal 8 site. We invoke this using "drush scr" while rolling back migrations as a workaround for migrate-rollback not being fully implemented in D8 yet. Could also be useful for awesome April Fool's Day pranks (just kidding, don't do that).
<?php
$query = \Drupal::entityQuery('node');
// Optionally, add the following line to delete only a certain type of node.
//->condition('type', 'event');
$nids = $query->execute();
$storage_handler = \Drupal::entityManager()->getStorage('node');
$entities = $storage_handler->loadMultiple($nids);
$storage_handler->delete($entities);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment