function simple_sitemap_engines_cron in Simple XML sitemap 4.x
Same name and namespace in other branches
- 8.3 modules/simple_sitemap_engines/simple_sitemap_engines.module \simple_sitemap_engines_cron()
Implements hook_cron().
If the sitemap submission interval has elapsed, adds each search engine to the submission queue to be processed.
See also
Drupal\simple_sitemap_engines\Plugin\QueueWorker\SitemapSubmitter
File
- modules/
simple_sitemap_engines/ simple_sitemap_engines.module, line 18 - Submits sitemaps to search engines.
Code
function simple_sitemap_engines_cron() {
$config = \Drupal::config('simple_sitemap_engines.settings');
if ($config
->get('enabled')) {
$interval = (int) $config
->get('submission_interval') * 60 * 60;
$request_time = \Drupal::time()
->getRequestTime();
foreach (SimpleSitemapEngine::loadMultiple() as $id => $engine) {
$last_submitted = \Drupal::state()
->get("simple_sitemap_engines.simple_sitemap_engine.{$id}.last_submitted", -1);
if ($last_submitted !== -1 && $last_submitted + $interval > $request_time) {
continue;
}
if (!empty($engine->sitemap_variants)) {
\Drupal::queue('simple_sitemap_engine_submit')
->createItem($id);
}
}
}
}