You are here

function delete_real_estate in Styled Google Map 8.2

Parameters

$context:

1 string reference to 'delete_real_estate'
styled_google_map_data_uninstall in modules/data/styled_google_map_data.install

File

modules/data/demo.batch.inc, line 61

Code

function delete_real_estate(&$context) {
  $storage = \Drupal::entityTypeManager()
    ->getStorage('real_estate');
  if (empty($context['sandbox'])) {
    $context['sandbox']['progress'] = 0;

    // Save data count for the termination message.
    $context['sandbox']['max'] = $storage
      ->getQuery()
      ->count()
      ->execute();
    $context['results']['max'] = $context['sandbox']['max'];
    $context['results']['created'] = [];
  }
  $ids = $storage
    ->getQuery()
    ->range(0, 100)
    ->execute();
  $context['results']['created'] = array_merge($context['results']['created'], $ids);
  $items = $storage
    ->loadMultiple($ids);
  $storage
    ->delete($items);

  // Update our progress information.
  $context['sandbox']['progress'] = $context['sandbox']['progress'] + count($items);
  if ($context['sandbox']['max']) {
    if ($context['sandbox']['progress'] <= $context['sandbox']['max']) {
      $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
    }
    else {
      $context['finished'] = 1;
    }
    $context['message'] = t('Running Batch, finished @percent%', [
      '@percent' => round($context['sandbox']['progress'] / $context['sandbox']['max'] * 100, 2),
    ]);
  }
  else {
    $context['finished'] = 1;
  }
}