You are here

function xmlsitemap_cron in XML sitemap 2.x

Same name and namespace in other branches
  1. 8 xmlsitemap.module \xmlsitemap_cron()
  2. 5.2 xmlsitemap/xmlsitemap.module \xmlsitemap_cron()
  3. 5 xmlsitemap.module \xmlsitemap_cron()
  4. 6.2 xmlsitemap.module \xmlsitemap_cron()
  5. 7.2 xmlsitemap.module \xmlsitemap_cron()

Implements hook_cron().

@todo Use new Queue system. Need to add {sitemap}.queued. @todo Regenerate one at a time?

1 call to xmlsitemap_cron()
XmlSitemapNodeFunctionalTest::testCron in tests/src/Functional/XmlSitemapNodeFunctionalTest.php
Test the import of old nodes via cron.

File

./xmlsitemap.module, line 182
xmlsitemap XML sitemap

Code

function xmlsitemap_cron() {

  // If cron sitemap file regeneration is disabled, stop.
  if (\Drupal::config('xmlsitemap.settings')
    ->get('disable_cron_regeneration')) {
    return;
  }

  // If there were no new or changed links, skip.
  if (!\Drupal::state()
    ->get('xmlsitemap_regenerate_needed')) {
    return;
  }

  // If the minimum sitemap lifetime hasn't been passed, skip.
  $lifetime = \Drupal::time()
    ->getRequestTime() - \Drupal::state()
    ->get('xmlsitemap_generated_last');
  if ($lifetime < \Drupal::config('xmlsitemap.settings')
    ->get('minimum_lifetime')) {
    return;
  }
  xmlsitemap_xmlsitemap_index_links(\Drupal::config('xmlsitemap.settings')
    ->get('batch_limit'));

  // Regenerate the sitemap XML files.
  xmlsitemap_run_unprogressive_batch('xmlsitemap_regenerate_batch');
}