function _entity_bulk_delete_batch in Entity Bulk Delete 7
Batch callback to bulk delete entities.
Parameters
EntityFieldQuery $query: The EntityFieldQuery object to retrieve the entities to delete.
int $limit: The amount of entities to delete at once.
bool $queue: If TRUE will queue the entities for deletion. If FALSE will immediately delete the entities.
array $context: The batch context.
1 string reference to '_entity_bulk_delete_batch'
- drush_entity_bulk_delete in ./
entity_bulk_delete.drush.inc - Command callback for drush entity-bulk-delete
File
- ./
entity_bulk_delete.drush.inc, line 105 - Drush integration for the Entity Bulk Delete module.
Code
function _entity_bulk_delete_batch(EntityFieldQuery $query, $limit, $queue, &$context) {
// Initialize context with progress information.
if (!isset($context['sandbox']['last_entity_id'])) {
$context['sandbox']['last_entity_id'] = 0;
}
$query
->entityCondition('entity_id', $context['sandbox']['last_entity_id'], '>');
$query
->range(0, $limit * ($queue ? 50 : 10));
$results = $query
->execute();
if (empty($results)) {
$context['finished'] = TRUE;
return;
}
foreach ($results as $entity_type => $entities) {
$chunks = array_chunk(array_keys($results[$entity_type]), $limit);
foreach ($chunks as $chunk) {
entity_bulk_delete($entity_type, $chunk, $queue);
}
$context['sandbox']['last_entity_id'] = max(array_keys($results[$entity_type]));
}
$context['finished'] = FALSE;
}