Skip to main content
added 13 characters in body
Source Link
Flo Develop
  • 769
  • 7
  • 13

AnOn Drupal 8, an other way is to delete multiple entities without loading them all at a time but by chunk.

You can use less memory and have great performance :

$nids = \Drupal::entityQuery("node")
  ->condition("type", "my_bundle")
  ->execute();

$storage_handler = \Drupal::entityTypeManager()->getStorage("node");

if (!empty($nids)) {
  foreach (array_chunk($nids, 50) as $chunk) {
    $nodes = $storage_handler->loadMultiple($chunk);
    $storage_handler->delete($nodes);
  }
};

For more convenience, you can trigger it inside drush command php-eval :

drush php-eval '$nids = \Drupal::entityQuery("node")->condition("type", "my_bundle")->execute(); $storage_handler = \Drupal::entityTypeManager()->getStorage("node"); if (!empty($nids)) {   foreach (array_chunk($nids, 50) as $chunk) { $nodes = $storage_handler->loadMultiple($chunk); $storage_handler->delete($nodes); }};'

An other way is to delete multiple entities without loading them all at a time but by chunk.

You can use less memory and have great performance :

$nids = \Drupal::entityQuery("node")
  ->condition("type", "my_bundle")
  ->execute();

$storage_handler = \Drupal::entityTypeManager()->getStorage("node");

if (!empty($nids)) {
  foreach (array_chunk($nids, 50) as $chunk) {
    $nodes = $storage_handler->loadMultiple($chunk);
    $storage_handler->delete($nodes);
  }
};

For more convenience, you can trigger it inside drush command php-eval :

drush php-eval '$nids = \Drupal::entityQuery("node")->condition("type", "my_bundle")->execute(); $storage_handler = \Drupal::entityTypeManager()->getStorage("node"); if (!empty($nids)) {   foreach (array_chunk($nids, 50) as $chunk) { $nodes = $storage_handler->loadMultiple($chunk); $storage_handler->delete($nodes); }};'

On Drupal 8, an other way is to delete multiple entities without loading them all at a time but by chunk.

You can use less memory and have great performance :

$nids = \Drupal::entityQuery("node")
  ->condition("type", "my_bundle")
  ->execute();

$storage_handler = \Drupal::entityTypeManager()->getStorage("node");

if (!empty($nids)) {
  foreach (array_chunk($nids, 50) as $chunk) {
    $nodes = $storage_handler->loadMultiple($chunk);
    $storage_handler->delete($nodes);
  }
};

For more convenience, you can trigger it inside drush command php-eval :

drush php-eval '$nids = \Drupal::entityQuery("node")->condition("type", "my_bundle")->execute(); $storage_handler = \Drupal::entityTypeManager()->getStorage("node"); if (!empty($nids)) {   foreach (array_chunk($nids, 50) as $chunk) { $nodes = $storage_handler->loadMultiple($chunk); $storage_handler->delete($nodes); }};'
added 406 characters in body
Source Link
Flo Develop
  • 769
  • 7
  • 13

An other way is to delete multiple entities without loading them all at a time but by chunk.

You can use less memory and have great performance :

$nids = \Drupal::entityQuery("node")
  ->condition("type", "my_bundle")
  ->execute();

$storage_handler = \Drupal::entityTypeManager()->getStorage("node");

if (!empty($nids)) {
  foreach (array_chunk($nids, 50) as $chunk) {
    $nodes = $storage_handler->loadMultiple($chunk);
    $storage_handler->delete($nodes);
  }
};

For more convenience, you can trigger it inside drush command php-eval :

drush php-eval '$nids = \Drupal::entityQuery("node")->condition("type", "my_bundle")->execute(); $storage_handler = \Drupal::entityTypeManager()->getStorage("node"); if (!empty($nids)) {   foreach (array_chunk($nids, 50) as $chunk) { $nodes = $storage_handler->loadMultiple($chunk); $storage_handler->delete($nodes); }};'

An other way is to delete multiple entities without loading them all at a time but by chunk.

You can use less memory and have great performance :

$nids = \Drupal::entityQuery("node")
  ->condition("type", "my_bundle")
  ->execute();

$storage_handler = \Drupal::entityTypeManager()->getStorage("node");

if (!empty($nids)) {
  foreach (array_chunk($nids, 50) as $chunk) {
    $nodes = $storage_handler->loadMultiple($chunk);
    $storage_handler->delete($nodes);
  }
};

An other way is to delete multiple entities without loading them all at a time but by chunk.

You can use less memory and have great performance :

$nids = \Drupal::entityQuery("node")
  ->condition("type", "my_bundle")
  ->execute();

$storage_handler = \Drupal::entityTypeManager()->getStorage("node");

if (!empty($nids)) {
  foreach (array_chunk($nids, 50) as $chunk) {
    $nodes = $storage_handler->loadMultiple($chunk);
    $storage_handler->delete($nodes);
  }
};

For more convenience, you can trigger it inside drush command php-eval :

drush php-eval '$nids = \Drupal::entityQuery("node")->condition("type", "my_bundle")->execute(); $storage_handler = \Drupal::entityTypeManager()->getStorage("node"); if (!empty($nids)) {   foreach (array_chunk($nids, 50) as $chunk) { $nodes = $storage_handler->loadMultiple($chunk); $storage_handler->delete($nodes); }};'
Source Link
Flo Develop
  • 769
  • 7
  • 13

An other way is to delete multiple entities without loading them all at a time but by chunk.

You can use less memory and have great performance :

$nids = \Drupal::entityQuery("node")
  ->condition("type", "my_bundle")
  ->execute();

$storage_handler = \Drupal::entityTypeManager()->getStorage("node");

if (!empty($nids)) {
  foreach (array_chunk($nids, 50) as $chunk) {
    $nodes = $storage_handler->loadMultiple($chunk);
    $storage_handler->delete($nodes);
  }
};