You are here

simple_sitemap_engines.module in Simple XML sitemap 8.3

Same filename and directory in other branches
  1. 4.x modules/simple_sitemap_engines/simple_sitemap_engines.module

Submits sitemaps to search engines.

File

modules/simple_sitemap_engines/simple_sitemap_engines.module
View source
<?php

/**
 * @file
 * Submits sitemaps to search engines.
 */

/**
 * Implements hook_cron().
 *
 * If the sitemap submission interval has elapsed, adds each search engine to
 * the submission queue to be processed.
 *
 * @see Drupal\simple_sitemap_engines\Plugin\QueueWorker\SitemapSubmitter
 */
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::service('datetime.time')
      ->getRequestTime();
    foreach (\Drupal::entityTypeManager()
      ->getStorage('simple_sitemap_engine')
      ->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);
      }
    }
  }
}

Functions

Namesort descending Description
simple_sitemap_engines_cron Implements hook_cron().