You are here

public function XmlSitemapCommands::index in XML sitemap 2.x

Same name and namespace in other branches
  1. 8 src/Commands/XmlSitemapCommands.php \Drupal\xmlsitemap\Commands\XmlSitemapCommands::index()

Process un-indexed XML sitemap links.

@option limit The limit of links of each type to process. @validate-module-enabled xmlsitemap

@command xmlsitemap:index @aliases xmlsitemap-index

Parameters

array $options: An associative array of options obtained from cli, aliases, config, etc.

File

src/Commands/XmlSitemapCommands.php, line 100

Class

XmlSitemapCommands
Drush commands for XML sitemap.

Namespace

Drupal\xmlsitemap\Commands

Code

public function index(array $options = [
  'limit' => NULL,
]) {
  $limit = (int) ($options['limit'] ?: $this->configFactory
    ->get('xmlsitemap.settings')
    ->get('batch_limit'));
  $count_before = $this->connection
    ->select('xmlsitemap', 'x')
    ->countQuery()
    ->execute()
    ->fetchField();
  $this->moduleHandler
    ->invokeAll('xmlsitemap_index_links', [
    'limit' => $limit,
  ]);
  $count_after = $this->connection
    ->select('xmlsitemap', 'x')
    ->countQuery()
    ->execute()
    ->fetchField();
  if ($count_after == $count_before) {
    $this
      ->output()
      ->writeln(dt('No new XML sitemap links to index.'));
  }
  else {
    $this
      ->output()
      ->writeln(dt('Indexed @count new XML sitemap links.', [
      '@count' => $count_after - $count_before,
    ]));
  }
}