public function LinkExtractorBatch::processEntities in Link checker 8
Process part of entities.
Parameters
int $numberOfItems: Number of items to process.
Return value
int Number of items that were processed.
1 call to LinkExtractorBatch::processEntities()
- LinkExtractorBatch::batchProcessEntities in src/LinkExtractorBatch.php 
- Process part of entities within a batch operation.
File
- src/LinkExtractorBatch.php, line 93 
Class
- LinkExtractorBatch
- Helper service to handle extraction index.
Namespace
Drupal\linkcheckerCode
public function processEntities($numberOfItems = 20) {
  $entityTypes = $this
    ->getEntityTypesToProcess();
  $numberOfProcessedItems = 0;
  foreach ($entityTypes as $entityTypeData) {
    /** @var \Drupal\Core\Entity\EntityTypeInterface $entityType */
    $entityType = $entityTypeData['entity_type'];
    $bundle = $entityTypeData['bundle'];
    $query = $this->database
      ->select($entityType
      ->getBaseTable(), 'base');
    $query
      ->fields('base', [
      $entityType
        ->getKey('id'),
    ]);
    $query
      ->leftJoin('linkchecker_index', 'i', 'i.entity_id = base.' . $entityType
      ->getKey('id') . ' AND i.entity_type = :entity_type', [
      ':entity_type' => $entityType
        ->id(),
    ]);
    $query
      ->isNull('i.entity_id');
    if (!empty($bundle)) {
      $query
        ->condition('base.' . $entityType
        ->getKey('bundle'), $bundle);
    }
    $query
      ->range(0, $numberOfItems - $numberOfProcessedItems);
    $ids = $query
      ->execute()
      ->fetchCol();
    $storage = $this->entityTypeManager
      ->getStorage($entityType
      ->id());
    foreach ($ids as $id) {
      $entity = $storage
        ->load($id);
      if ($entity instanceof FieldableEntityInterface) {
        $links = $this->extractor
          ->extractFromEntity($entity);
        $this->extractor
          ->saveLinkMultiple($links);
        $this->extractor
          ->updateEntityExtractIndex($entity);
      }
      $numberOfProcessedItems++;
    }
    if ($numberOfProcessedItems >= $numberOfItems) {
      break;
    }
  }
  return $numberOfProcessedItems;
}