You are here

protected function QueueWorker::generateVariantChunksFromResults in Simple XML sitemap 4.x

Same name and namespace in other branches
  1. 8.3 src/Queue/QueueWorker.php \Drupal\simple_sitemap\Queue\QueueWorker::generateVariantChunksFromResults()

Parameters

bool $complete:

1 call to QueueWorker::generateVariantChunksFromResults()
QueueWorker::generateSitemap in src/Queue/QueueWorker.php

File

src/Queue/QueueWorker.php, line 308

Class

QueueWorker

Namespace

Drupal\simple_sitemap\Queue

Code

protected function generateVariantChunksFromResults(bool $complete = FALSE) : void {
  if (!empty($this->results)) {
    $processed_results = $this->results;
    $variant_id = $this->variantProcessedNow
      ->id();
    $this->moduleHandler
      ->alter('simple_sitemap_links', $processed_results, $variant_id);

    // todo Context could be sitemap object instead?
    $this->processedResults = array_merge($this->processedResults, $processed_results);
    $this->results = [];
  }
  if (empty($this->processedResults)) {
    return;
  }
  if (!empty($this->maxLinks)) {
    foreach (array_chunk($this->processedResults, $this->maxLinks, TRUE) as $chunk_links) {
      if ($complete || count($chunk_links) === $this->maxLinks) {
        $this->variantProcessedNow
          ->addChunk($chunk_links);
        $this->processedResults = array_diff_key($this->processedResults, $chunk_links);
      }
    }
  }
  else {
    $this->variantProcessedNow
      ->addChunk($this->processedResults);
    $this->processedResults = [];
  }
}