You are here

public function SitemapGeneratorBase::generateIndex in Simple XML sitemap 8.3

Return value

$this

Throws

\Exception

Overrides SitemapGeneratorInterface::generateIndex

File

src/Plugin/simple_sitemap/SitemapGenerator/SitemapGeneratorBase.php, line 250

Class

SitemapGeneratorBase
Class SitemapGeneratorBase @package Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator

Namespace

Drupal\simple_sitemap\Plugin\simple_sitemap\SitemapGenerator

Code

public function generateIndex() {
  if (!empty($chunk_info = $this
    ->getChunkInfo()) && count($chunk_info) > 1) {
    $index_xml = $this
      ->getIndexXml($chunk_info);
    $highest_id = $this->db
      ->query('SELECT MAX(id) FROM {simple_sitemap}')
      ->fetchField();
    $this->db
      ->merge('simple_sitemap')
      ->keys([
      'delta' => self::INDEX_DELTA,
      'type' => $this->sitemapVariant,
      'status' => 0,
    ])
      ->insertFields([
      'id' => NULL === $highest_id ? 0 : $highest_id + 1,
      'delta' => self::INDEX_DELTA,
      'type' => $this->sitemapVariant,
      'sitemap_string' => $index_xml,
      'sitemap_created' => $this->time
        ->getRequestTime(),
      'status' => 0,
    ])
      ->updateFields([
      'sitemap_string' => $index_xml,
      'sitemap_created' => $this->time
        ->getRequestTime(),
    ])
      ->execute();
  }
  return $this;
}