Last active
August 29, 2015 14:27
-
-
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).
This file contains 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 | |
$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