You are here

public function RadioactivityProcessor::processIncidents in Radioactivity 8.3

Same name and namespace in other branches
  1. 4.0.x src/RadioactivityProcessor.php \Drupal\radioactivity\RadioactivityProcessor::processIncidents()

Process emits from the queue.

Return value

int The number of emits processed.

Overrides RadioactivityProcessorInterface::processIncidents

File

src/RadioactivityProcessor.php, line 260

Class

RadioactivityProcessor
Class RadioactivityProcessor.

Namespace

Drupal\radioactivity

Code

public function processIncidents() {
  $resultCount = 0;
  $incidentsByType = $this->storage
    ->getIncidentsByType();
  $this->storage
    ->clearIncidents();
  foreach ($incidentsByType as $entityType => $incidents) {

    // Delegate processing to a queue worker to prevent memory errors when
    // large number of entities are processed.
    $chunks = array_chunk($incidents, self::QUEUE_CHUNK_SIZE, TRUE);
    foreach ($chunks as $chunk) {
      $queue = $this->queue
        ->get(self::QUEUE_WORKER_INCIDENTS);
      $queue
        ->createItem([
        'entity_type' => $entityType,
        'incidents' => $chunk,
      ]);
    }
    $resultCount += count($incidents);
  }
  $this->log
    ->notice('Processed @count radioactivity incidents.', [
    '@count' => $resultCount,
  ]);
  return $resultCount;
}