public function QueueWorker::generateSitemap in Simple XML sitemap 8.3
Same name and namespace in other branches
- 4.x src/Queue/QueueWorker.php \Drupal\simple_sitemap\Queue\QueueWorker::generateSitemap()
Parameters
string $from:
Return value
$this
Throws
\Drupal\Component\Plugin\Exception\PluginException
File
- src/
Queue/ QueueWorker.php, line 217
Class
Namespace
Drupal\simple_sitemap\QueueCode
public function generateSitemap($from = self::GENERATE_TYPE_FORM) {
$this->generatorSettings = [
'base_url' => $this->settings
->getSetting('base_url', ''),
'xsl' => $this->settings
->getSetting('xsl', TRUE),
'default_variant' => $this->settings
->getSetting('default_variant', NULL),
'skip_untranslated' => $this->settings
->getSetting('skip_untranslated', FALSE),
'remove_duplicates' => $this->settings
->getSetting('remove_duplicates', TRUE),
'excluded_languages' => $this->settings
->getSetting('excluded_languages', []),
];
$this->maxLinks = $this->settings
->getSetting('max_links');
$max_execution_time = $this->settings
->getSetting('generate_duration', 10000);
Timer::start('simple_sitemap_generator');
$this
->unstashResults();
if (!$this
->generationInProgress()) {
$this
->rebuildQueue();
}
// Acquire a lock for max execution time + 5 seconds. If max_execution time
// is unlimited then lock for 1 hour.
$lock_timeout = $max_execution_time > 0 ? $max_execution_time / 1000 + 5 : static::GENERATE_LOCK_TIMEOUT;
if (!$this->lock
->acquire(static::LOCK_ID, $lock_timeout)) {
throw new \RuntimeException('Unable to acquire a lock for sitemap generation');
}
foreach ($this->queue
->yieldItem() as $element) {
if (!empty($max_execution_time) && Timer::read('simple_sitemap_generator') >= $max_execution_time) {
break;
}
try {
if ($element->data['sitemap_variant'] !== $this->variantProcessedNow) {
if (NULL !== $this->variantProcessedNow) {
$this
->generateVariantChunksFromResults(TRUE);
$this
->publishCurrentVariant();
}
$this->variantProcessedNow = $element->data['sitemap_variant'];
$this->generatorProcessedNow = $element->data['sitemap_generator'];
$this->processedPaths = [];
}
$this
->generateResultsFromElement($element);
if (!empty($this->maxLinks) && count($this->results) >= $this->maxLinks) {
$this
->generateVariantChunksFromResults();
}
} catch (\Exception $e) {
watchdog_exception('simple_sitemap', $e);
}
$this->queue
->deleteItem($element);
//todo May want to use deleteItems() instead.
$this->elementsRemaining--;
}
if ($this
->getQueuedElementCount() === 0) {
$this
->generateVariantChunksFromResults(TRUE);
$this
->publishCurrentVariant();
}
else {
$this
->stashResults();
}
$this->lock
->release(static::LOCK_ID);
return $this;
}