public function QueueWorker::queue in Simple XML sitemap 8.3
Same name and namespace in other branches
- 4.x src/Queue/QueueWorker.php \Drupal\simple_sitemap\Queue\QueueWorker::queue()
Parameters
string[]|string|null $variants:
Return value
$this
Throws
\Drupal\Component\Plugin\Exception\PluginException
1 call to QueueWorker::queue()
- QueueWorker::rebuildQueue in src/
Queue/ QueueWorker.php
File
- src/
Queue/ QueueWorker.php, line 138
Class
Namespace
Drupal\simple_sitemap\QueueCode
public function queue($variants = NULL) {
$type_definitions = $this->manager
->getSitemapTypes();
$all_data_sets = [];
// Gather variant data of variants chosen for this rebuild.
$queue_variants = NULL === $variants ? $this->manager
->getSitemapVariants() : array_filter($this->manager
->getSitemapVariants(), static function ($name) use ($variants) {
return in_array($name, (array) $variants);
}, ARRAY_FILTER_USE_KEY);
foreach ($queue_variants as $variant_name => $variant_definition) {
$type = $variant_definition['type'];
// Adding generate_sitemap operations for all data sets.
foreach ($type_definitions[$type]['urlGenerators'] as $url_generator_id) {
$data_sets = $this->manager
->getUrlGenerator($url_generator_id)
->setSitemapVariant($variant_name)
->getDataSets();
if (!empty($data_sets)) {
$queue_variants[$variant_name]['data'] = TRUE;
foreach ($data_sets as $data_set) {
$all_data_sets[] = [
'data' => $data_set,
'sitemap_variant' => $variant_name,
'url_generator' => $url_generator_id,
'sitemap_generator' => $type_definitions[$type]['sitemapGenerator'],
];
if (count($all_data_sets) === self::REBUILD_QUEUE_CHUNK_ITEM_SIZE) {
$this
->queueElements($all_data_sets);
$all_data_sets = [];
}
}
}
}
}
if (!empty($all_data_sets)) {
$this
->queueElements($all_data_sets);
}
$this
->getQueuedElementCount(TRUE);
// Remove all sitemap instances of variants which did not yield any queue elements.
$this->manager
->removeSitemap(array_keys(array_filter($queue_variants, static function ($e) {
return empty($e['data']);
})));
return $this;
}