You are here

public static function RemoveGatherContentLocalData::deleteAllEntity in GatherContent 8.4

Delete gathercontent_operation and gathercontent_operation_item entities.

Parameters

string $entity_type_id: Entity type ID of which we want to delete entities.

array $context: Array of context.

File

gathercontent_ui/src/Form/RemoveGatherContentLocalData.php, line 71

Class

RemoveGatherContentLocalData
Class RemoveGatherContentLocalData.

Namespace

Drupal\gathercontent_ui\Form

Code

public static function deleteAllEntity($entity_type_id, array &$context) {
  $entity_type_manager = \Drupal::entityTypeManager();
  if (empty($context['sandbox'])) {
    $context['sandbox']['num_of_deleted_items'] = 0;
    $context['sandbox']['current_id'] = 0;
    $context['sandbox']['total_count'] = \Drupal::entityQuery($entity_type_id)
      ->count()
      ->execute();
  }
  $steps = 50;
  $entity_ids = \Drupal::entityQuery($entity_type_id)
    ->condition($entity_type_manager
    ->getDefinition($entity_type_id)
    ->getKey('id'), $context['sandbox']['current_id'], '>')
    ->sort($entity_type_manager
    ->getDefinition($entity_type_id)
    ->getKey('id'))
    ->range(0, $steps)
    ->execute();
  foreach ($entity_ids as $entity_id) {
    $context['sandbox']['num_of_deleted_items']++;
    $context['sandbox']['current_id'] = $entity_id;
    $entity_type_manager
      ->getStorage($entity_type_id)
      ->load($entity_id)
      ->delete();
  }
  if ($context['sandbox']['num_of_deleted_items'] != $context['sandbox']['total_count']) {
    $context['finished'] = $context['sandbox']['num_of_deleted_items'] / $context['sandbox']['total_count'];
  }
}