Skip to content

Instantly share code, notes, and snippets.

@andriyun
Last active January 11, 2022 09:21
Show Gist options
  • Save andriyun/a46913ced0573e121818b6ba4c2e97c7 to your computer and use it in GitHub Desktop.
Save andriyun/a46913ced0573e121818b6ba4c2e97c7 to your computer and use it in GitHub Desktop.
Delete entities from drupal via drush

Delete any entity in drupal

drush ev "entity_delete_multiple('v', \Drupal::entityQuery('entity_type_name')->execute());"

Delete node with pecific type

drush ev "entity_delete_multiple('node', \Drupal::entityQuery('node')->condition('type', 'node_type')->execute());"

Delete BIG amount of entities

drush ev '$entity_type = "entity_type_name";$files = \Drupal::entityQuery($entity_type)->execute();foreach (array_chunk($files, 1000) as $chunk_num => $chunk) { $storage_handler = \Drupal::entityTypeManager()->getStorage($entity_type); $entities = $storage_handler->loadMultiple($chunk);$storage_handler->delete($entities); print_r("Deleted: " . ($chunk_num + 1) * 1000 . PHP_EOL);}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment