You are here

public function SitemapGeneratorBase::generate in Simple XML sitemap 8.3

Parameters

array $links:

Return value

$this

Throws

\Exception

Overrides SitemapGeneratorInterface::generate

File

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

Class

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

Namespace

Drupal\simple_sitemap\Plugin\simple_sitemap\SitemapGenerator

Code

public function generate(array $links) {
  $highest_id = $this->db
    ->query('SELECT MAX(id) FROM {simple_sitemap}')
    ->fetchField();
  $highest_delta = $this->db
    ->query('SELECT MAX(delta) FROM {simple_sitemap} WHERE type = :type AND status = :status', [
    ':type' => $this->sitemapVariant,
    ':status' => 0,
  ])
    ->fetchField();
  $this->db
    ->insert('simple_sitemap')
    ->fields([
    'id' => NULL === $highest_id ? 0 : $highest_id + 1,
    'delta' => NULL === $highest_delta ? self::FIRST_CHUNK_DELTA : $highest_delta + 1,
    'type' => $this->sitemapVariant,
    'sitemap_string' => $this
      ->getXml($links),
    'sitemap_created' => $this->time
      ->getRequestTime(),
    'status' => 0,
    'link_count' => count($links),
  ])
    ->execute();
  return $this;
}