You are here

public function LinkCleanUp::batchProcessDelete in Link checker 8

Proccess link deletion within batch operation.

Parameters

mixed $context: Batch context.

File

src/LinkCleanUp.php, line 87

Class

LinkCleanUp
Class LinkCleanUp.

Namespace

Drupal\linkchecker

Code

public function batchProcessDelete(&$context) {
  $storage = $this->entityTypeManager
    ->getStorage('linkcheckerlink');
  if (!isset($context['sandbox']['total'])) {
    $context['sandbox']['total'] = $storage
      ->getQuery()
      ->count()
      ->execute();
  }
  $ids = $storage
    ->getQuery()
    ->range(0, 10)
    ->execute();
  $this
    ->processDelete($ids);

  // Count how many items are not proceed.
  $toProcess = $storage
    ->getQuery()
    ->count()
    ->execute();
  $context['sandbox']['current'] = $context['sandbox']['total'] - $toProcess;
  if (!empty($toProcess)) {
    $context['finished'] = $context['sandbox']['current'] / $context['sandbox']['total'];
  }
  else {
    $context['finished'] = 1;
  }
}