You are here

function simple_sitemap_views_cron in Simple XML sitemap (Views integration) 8

Implements hook_cron().

File

./simple_sitemap_views.module, line 11
Contains simple_sitemap_views.module.

Code

function simple_sitemap_views_cron() {

  // The task queue of garbage collection in the index.
  $queue = \Drupal::queue('simple_sitemap_views_garbage_collector');

  // Check that the queue is empty.
  if (!$queue
    ->numberOfItems()) {

    // Get identifiers of indexed views.
    $query = \Drupal::database()
      ->select('simple_sitemap_views', 'ssv');
    $query
      ->addField('ssv', 'view_id');
    $query
      ->distinct();
    $result = $query
      ->execute()
      ->fetchCol();

    // Create a garbage collection task.
    foreach ($result as $view_id) {
      $queue
        ->createItem([
        'view_id' => $view_id,
      ]);
    }
  }
}