Commit d4b538da authored by gbyte.co's avatar gbyte.co Committed by gbyte.co

Issue #2961233 by gbyte.co: Allow for multiple sitemap types on one Drupal instance

parent f0ea8767
...@@ -2,7 +2,7 @@ max_links: 2000 ...@@ -2,7 +2,7 @@ max_links: 2000
cron_generate: true cron_generate: true
cron_generate_interval: 0 cron_generate_interval: 0
remove_duplicates: true remove_duplicates: true
skip_untranslated: false skip_untranslated: true
batch_process_limit: 1500 batch_process_limit: 1500
base_url: '' base_url: ''
custom_links_include_images: false custom_links_include_images: false
......
label: 'Default hreflang'
description: 'The default hreflang sitemap type.'
sitemap_generator: 'default'
url_generators:
- 'custom'
- 'entity'
- 'entity_menu_link_content'
- 'arbitrary'
variants:
default:
label: 'Default'
type: 'default_hreflang'
...@@ -25,13 +25,13 @@ simple_sitemap.settings: ...@@ -25,13 +25,13 @@ simple_sitemap.settings:
custom_links_include_images: custom_links_include_images:
label: 'Include images of custom links' label: 'Include images of custom links'
type: boolean type: boolean
enabled_entity_types: excluded_languages:
label: 'Enabled entity types' label: 'Excluded languages'
type: sequence type: sequence
sequence: sequence:
type: string type: string
excluded_languages: enabled_entity_types:
label: 'Excluded languages' label: 'Enabled entity types'
type: sequence type: sequence
sequence: sequence:
type: string type: string
...@@ -72,3 +72,39 @@ simple_sitemap.custom: ...@@ -72,3 +72,39 @@ simple_sitemap.custom:
changefreq: changefreq:
label: 'Change frequency' label: 'Change frequency'
type: string type: string
simple_sitemap.types.*:
label: 'Sitemap types'
type: config_object
mapping:
label:
label: 'Type label'
type: string
description:
label: 'Type description'
type: string
sitemap_generator:
label: 'Sitemap generator'
type: string
url_generators:
label: 'URL generators'
type: sequence
sequence:
type: string
simple_sitemap.variants:
label: 'Sitemap variants'
type: config_object
mapping:
variants:
label: 'Sitemap variants'
type: sequence
sequence:
type: mapping
mapping:
label:
label: 'Variant label'
type: string
type:
label: 'Sitemap type'
type: string
...@@ -15,9 +15,13 @@ ...@@ -15,9 +15,13 @@
* This hook gets invoked for every sitemap chunk generated. * This hook gets invoked for every sitemap chunk generated.
* *
* @param array &$links * @param array &$links
* Array containing multilingual links generated for each path to be indexed. * Array containing multilingual links generated for each path to be indexed
*
* @param string|null $sitemap_variant
*
* @todo Make work for sitemap types.
*/ */
function hook_simple_sitemap_links_alter(array &$links) { function hook_simple_sitemap_links_alter(array &$links, $sitemap_variant) {
// Remove German URL for a certain path in the hreflang sitemap. // Remove German URL for a certain path in the hreflang sitemap.
foreach ($links as $key => $link) { foreach ($links as $key => $link) {
...@@ -43,12 +47,13 @@ function hook_simple_sitemap_links_alter(array &$links) { ...@@ -43,12 +47,13 @@ function hook_simple_sitemap_links_alter(array &$links) {
* Add arbitrary links to the sitemap. * Add arbitrary links to the sitemap.
* *
* @param array &$arbitrary_links * @param array &$arbitrary_links
* @param string|null $sitemap_variant
*/ */
function hook_simple_sitemap_arbitrary_links_alter(array &$arbitrary_links) { function hook_simple_sitemap_arbitrary_links_alter(array &$arbitrary_links, $sitemap_variant) {
// Add an arbitrary link. // Add an arbitrary link to all sitemap variants.
$arbitrary_links[] = [ $arbitrary_links[] = [
'url' => 'http://this-is-your-life.net/tyler', 'url' => 'http://some-arbitrary-link/',
'priority' => '0.5', 'priority' => '0.5',
// An ISO8601 formatted date. // An ISO8601 formatted date.
...@@ -66,6 +71,15 @@ function hook_simple_sitemap_arbitrary_links_alter(array &$arbitrary_links) { ...@@ -66,6 +71,15 @@ function hook_simple_sitemap_arbitrary_links_alter(array &$arbitrary_links) {
'de' => 'http://this-is-your-life.net/en/tyler', 'de' => 'http://this-is-your-life.net/en/tyler',
] ]
]; ];
// Add an arbitrary link to the 'fight_club' sitemap variant only.
switch ($sitemap_variant) {
case 'fight_club':
$arbitrary_links[] = [
'url' => 'http://this-is-your-life.net/tyler',
];
break;
}
} }
/** /**
...@@ -73,8 +87,9 @@ function hook_simple_sitemap_arbitrary_links_alter(array &$arbitrary_links) { ...@@ -73,8 +87,9 @@ function hook_simple_sitemap_arbitrary_links_alter(array &$arbitrary_links) {
* Attributes can be added, changed and removed. * Attributes can be added, changed and removed.
* *
* @param array &$attributes * @param array &$attributes
* @param string|null $sitemap_variant
*/ */
function hook_simple_sitemap_attributes_alter(array &$attributes) { function hook_simple_sitemap_attributes_alter(array &$attributes, $sitemap_variant) {
// Remove the xhtml attribute e.g. if no xhtml sitemap elements are present. // Remove the xhtml attribute e.g. if no xhtml sitemap elements are present.
unset($attributes['xmlns:xhtml']); unset($attributes['xmlns:xhtml']);
...@@ -85,8 +100,9 @@ function hook_simple_sitemap_attributes_alter(array &$attributes) { ...@@ -85,8 +100,9 @@ function hook_simple_sitemap_attributes_alter(array &$attributes) {
* Attributes can be added, changed and removed. * Attributes can be added, changed and removed.
* *
* @param array &$index_attributes * @param array &$index_attributes
* @param string|null $sitemap_variant
*/ */
function hook_simple_sitemap_index_attributes_alter(array &$index_attributes) { function hook_simple_sitemap_index_attributes_alter(array &$index_attributes, $sitemap_variant) {
// Add some attribute to the sitemap index. // Add some attribute to the sitemap index.
$index_attributes['name'] = 'value'; $index_attributes['name'] = 'value';
...@@ -95,16 +111,67 @@ function hook_simple_sitemap_index_attributes_alter(array &$index_attributes) { ...@@ -95,16 +111,67 @@ function hook_simple_sitemap_index_attributes_alter(array &$index_attributes) {
/** /**
* Alter properties of and remove generator plugins. * Alter properties of and remove generator plugins.
* *
* @param array $generators * @param array $url_generators
*/ */
function hook_simple_sitemap_url_generators_alter(array &$generators) { function hook_simple_sitemap_url_generators_alter(array &$url_generators) {
// Remove the entity generator. // Remove the entity generator.
// Useful when creating your own entity generator plugin. unset($url_generators['entity']);
unset($generators['entity']); }
/**
* Alter properties of and remove generator plugins.
*
* @param array $sitemap_generators
*/
function hook_simple_sitemap_sitemap_generators_alter(array &$sitemap_generators) {
// Remove the default generator.
unset($sitemap_generators['default']);
}
/**
* @param array $sitemap_types
*/
function hook_simple_sitemap_types_alter(array &$sitemap_types) {
// Remove the custom links generator from the default sitemap type definition.
$key = array_search('custom', $sitemap_types['default_hreflang']['url_generators']);
unset($sitemap_types['default_hreflang']['url_generators'][$key]);
// Define a new sitemap type to be generated with the default sitemap generator.
// Make it use only the custom and arbitrary link generators.
$sitemap_types['fight_club_sitemap_type'] = [
'label' => t('Fight Club Sitemap'),
'description' => t('The second rule of Fight Club is...'),
'sitemap_generator' => 'default',
'url_generators' => [
'custom',
'arbitrary',
],
];
}
/**
* @param array $variants
*/
function hook_simple_sitemap_variants_alter(array &$variants) {
// Add a new sitemap variant of the 'fight_club_sitemap_type' type.
$variants['fight_club'] = [
'type' => 'fight_club_sitemap_type',
'label' => t('Fight Club'),
];
}
/**
* @param $bundle_settings
* @param $entity_type_id
* @param $bundle_name
*/
function hook_simple_sitemap_bundle_settings_alter(array &$bundle_settings, $entity_type_id, $bundle_name) {
// Change the weight of the arbitrary link generator.
$generators['arbitrary']['weight'] = -100;
} }
/** /**
......
...@@ -30,7 +30,7 @@ function simple_sitemap_requirements($phase) { ...@@ -30,7 +30,7 @@ function simple_sitemap_requirements($phase) {
case 'runtime': case 'runtime':
$generator = \Drupal::service('simple_sitemap.generator'); $generator = \Drupal::service('simple_sitemap.generator');
$generated_ago = $generator->getGeneratedAgo(SitemapGeneratorBase::DEFAULT_SITEMAP_TYPE); //todo $generated_ago = $generator->getGeneratedAgo(SitemapGeneratorBase::DEFAULT_SITEMAP_VARIANT); //todo
$cron_generation = $generator->getSetting('cron_generate'); $cron_generation = $generator->getSetting('cron_generate');
if (!$generated_ago) { if (!$generated_ago) {
...@@ -450,4 +450,36 @@ function simple_sitemap_update_8210() { ...@@ -450,4 +450,36 @@ function simple_sitemap_update_8210() {
return t('The XML sitemap needs to be regenerated.'); return t('The XML sitemap needs to be regenerated.');
} }
/**
* Adding simple_sitemap.variants and simple_sitemap.types to configuration.
*/
function simple_sitemap_update_8211() {
$config_factory = \Drupal::service('config.factory');
// Add simple_sitemap.types.
$config_factory
->getEditable('simple_sitemap.types.default_hreflang')
->setData([
'label' => 'Default hreflang',
'description' => 'The default hreflang sitemap type.',
'sitemap_generator' => 'default',
'url_generators' => [
'custom',
'entity',
'entity_menu_link_content',
'arbitrary',
],
])->save();
// Add simple_sitemap.variants.
$config_factory
->getEditable('simple_sitemap.variants')
->set('variants', [
'default' => [
'label' => 'Default',
'type' => 'default_hreflang',
]
])->save();
}
...@@ -5,29 +5,29 @@ simple_sitemap.sitemap_default: ...@@ -5,29 +5,29 @@ simple_sitemap.sitemap_default:
requirements: requirements:
_access: 'TRUE' _access: 'TRUE'
simple_sitemap.sitemap_type: simple_sitemap.sitemap_variant:
path: '/sitemaps/{type}/sitemap.xml' path: '/sitemaps/{variant}/sitemap.xml'
defaults: defaults:
_controller: '\Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap' _controller: '\Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap'
requirements: requirements:
_access: 'TRUE' _access: 'TRUE'
simple_sitemap.sitemap_type_fallback: simple_sitemap.sitemap_variant_fallback:
path: '/sitemaps/{type}' path: '/sitemaps/{variant}'
defaults: defaults:
_controller: '\Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap' _controller: '\Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap'
requirements: requirements:
_access: 'TRUE' _access: 'TRUE'
simple_sitemap.sitemap_type_delta: simple_sitemap.sitemap_variant_delta:
path: '/sitemaps/{type}/{delta}/sitemap.xml' path: '/sitemaps/{variant}/{delta}/sitemap.xml'
defaults: defaults:
_controller: '\Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap' _controller: '\Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap'
requirements: requirements:
_access: 'TRUE' _access: 'TRUE'
simple_sitemap.sitemap_type_delta_fallback: simple_sitemap.sitemap_variant_delta_fallback:
path: '/sitemaps/{type}/{delta}' path: '/sitemaps/{variant}/{delta}'
defaults: defaults:
_controller: '\Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap' _controller: '\Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap'
requirements: requirements:
......
...@@ -10,6 +10,7 @@ services: ...@@ -10,6 +10,7 @@ services:
- '@path.validator' - '@path.validator'
- '@date.formatter' - '@date.formatter'
- '@datetime.time' - '@datetime.time'
- '@module_handler'
- '@simple_sitemap.batch' - '@simple_sitemap.batch'
- '@plugin.manager.simple_sitemap.url_generator' - '@plugin.manager.simple_sitemap.url_generator'
- '@plugin.manager.simple_sitemap.sitemap_generator' - '@plugin.manager.simple_sitemap.sitemap_generator'
......
...@@ -41,26 +41,10 @@ class SitemapGenerator extends Plugin { ...@@ -41,26 +41,10 @@ class SitemapGenerator extends Plugin {
*/ */
public $description; public $description;
/**
* An integer to determine the weight of this generator relative to others.
*
* @var int
*/
public $weight = 0;
/**
* Whether the generator is enabled by default.
*
* @var bool
*/
public $enabled = TRUE;
/** /**
* Default generator settings. * Default generator settings.
* *
* @var array * @var array
*/ */
public $settings = [ public $settings = [];
'default' => FALSE,
];
} }
...@@ -41,26 +41,10 @@ class UrlGenerator extends Plugin { ...@@ -41,26 +41,10 @@ class UrlGenerator extends Plugin {
*/ */
public $description; public $description;
/**
* An integer to determine the weight of this generator relative to others.
*
* @var int
*/
public $weight = 0;
/**
* Whether the generator is enabled by default.
*
* @var bool
*/
public $enabled = TRUE;
/** /**
* Default generator settings. * Default generator settings.
* *
* @var array * @var array
*/ */
public $settings = [ public $settings = [];
'default_sitemap_generator' => 'default',
];
} }
...@@ -81,6 +81,8 @@ class Batch { ...@@ -81,6 +81,8 @@ class Batch {
->setContext($context) ->setContext($context)
->setSettings($arguments['settings']) ->setSettings($arguments['settings'])
->setBatchMeta($batch_meta) ->setBatchMeta($batch_meta)
->setSitemapVariant($arguments['variant'])
->setSitemapGeneratorId($arguments['sitemap_generator'])
->generate($arguments['data_set']); ->generate($arguments['data_set']);
} }
...@@ -97,6 +99,7 @@ class Batch { ...@@ -97,6 +99,7 @@ class Batch {
\Drupal::service('plugin.manager.simple_sitemap.sitemap_generator') \Drupal::service('plugin.manager.simple_sitemap.sitemap_generator')
->createInstance($arguments['sitemap_generator']) ->createInstance($arguments['sitemap_generator'])
->setSettings($arguments['settings']) ->setSettings($arguments['settings'])
->setSitemapVariant($arguments['variant'])
->generateIndex(); ->generateIndex();
} }
...@@ -112,6 +115,7 @@ class Batch { ...@@ -112,6 +115,7 @@ class Batch {
public static function removeSitemap(array $arguments, array $batch_meta, &$context) { public static function removeSitemap(array $arguments, array $batch_meta, &$context) {
\Drupal::service('plugin.manager.simple_sitemap.sitemap_generator') \Drupal::service('plugin.manager.simple_sitemap.sitemap_generator')
->createInstance($arguments['sitemap_generator']) ->createInstance($arguments['sitemap_generator'])
->setSitemapVariant($arguments['variant'])
->remove(); ->remove();
} }
......
...@@ -48,13 +48,14 @@ class SimplesitemapController extends ControllerBase { ...@@ -48,13 +48,14 @@ class SimplesitemapController extends ControllerBase {
} }
/** /**
* Returns the whole sitemap of a certain type, its requested sitemap chunk, * Returns the whole sitemap variant, its requested chunk,
* or its sitemap index file. * or its sitemap index file.
* Caches the response in case of expected output, prevents caching otherwise. * Caches the response in case of expected output, prevents caching otherwise.
* *
* @param string $type * @param string $variant
* Optional name of sitemap type. This corresponds to the plugin ID * Optional name of sitemap variant.
* of the sitemap generator plugin to be responsible for the generation. * @see \hook_simple_sitemap_variants_alter()
* @see Simplesitemap::getSitemapVariants()
* *
* @param int $delta * @param int $delta
* Optional delta of the sitemap chunk. If none provided, the first chunk or * Optional delta of the sitemap chunk. If none provided, the first chunk or
...@@ -65,8 +66,8 @@ class SimplesitemapController extends ControllerBase { ...@@ -65,8 +66,8 @@ class SimplesitemapController extends ControllerBase {
* @return object * @return object
* Returns an XML response. * Returns an XML response.
*/ */
public function getSitemap($type = SitemapGeneratorBase::DEFAULT_SITEMAP_TYPE, $delta = NULL) { public function getSitemap($variant = SitemapGeneratorBase::DEFAULT_SITEMAP_VARIANT, $delta = NULL) {
$output = $this->generator->getSitemap($type, $delta); $output = $this->generator->getSitemap($variant, $delta);
if (!$output) { if (!$output) {
$this->cacheKillSwitch->trigger(); $this->cacheKillSwitch->trigger();
throw new NotFoundHttpException(); throw new NotFoundHttpException();
......
...@@ -16,10 +16,6 @@ use Drupal\Component\Datetime\Time; ...@@ -16,10 +16,6 @@ use Drupal\Component\Datetime\Time;
* id = "default", * id = "default",
* title = @Translation("Default sitemap generator"), * title = @Translation("Default sitemap generator"),
* description = @Translation("Generates a standard conform hreflang sitemap of your content."), * description = @Translation("Generates a standard conform hreflang sitemap of your content."),
* weight = 0,
* settings = {
* "default" = true,
* },
* ) * )
*/ */
class DefaultSitemapGenerator extends SitemapGeneratorBase { class DefaultSitemapGenerator extends SitemapGeneratorBase {
...@@ -108,16 +104,19 @@ class DefaultSitemapGenerator extends SitemapGeneratorBase { ...@@ -108,16 +104,19 @@ class DefaultSitemapGenerator extends SitemapGeneratorBase {
$this->writer->startElement('urlset'); $this->writer->startElement('urlset');
// Add attributes to document. // Add attributes to document.
$attributes = self::$attributes;
if (!$this->isHreflangSitemap()) { if (!$this->isHreflangSitemap()) {
unset(self::$attributes['xmlns:xhtml']); unset($attributes['xmlns:xhtml']);
} }
$this->moduleHandler->alter('simple_sitemap_attributes', self::$attributes); $sitemap_variant = $this->sitemapVariant;
foreach (self::$attributes as $name => $value) { $this->moduleHandler->alter('simple_sitemap_attributes', $attributes, $sitemap_variant);
foreach ($attributes as $name => $value) {
$this->writer->writeAttribute($name, $value); $this->writer->writeAttribute($name, $value);
} }
// Add URLs to document. // Add URLs to document.
$this->moduleHandler->alter('simple_sitemap_links', $links); $sitemap_variant = $this->sitemapVariant;
$this->moduleHandler->alter('simple_sitemap_links', $links, $sitemap_variant);
foreach ($links as $link) { foreach ($links as $link) {
// Add each translation variant URL as location to the sitemap. // Add each translation variant URL as location to the sitemap.
......
...@@ -17,7 +17,11 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S ...@@ -17,7 +17,11 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
const FIRST_CHUNK_DELTA = 1; const FIRST_CHUNK_DELTA = 1;
const INDEX_DELTA = 0; const INDEX_DELTA = 0;
const DEFAULT_SITEMAP_TYPE = 'default';
// todo Move this to Simplesitemap class?
const DEFAULT_SITEMAP_VARIANT = 'default';
const DEFAULT_SITEMAP_TYPE = 'default_hreflang';
const GENERATED_BY = 'Generated by the Simple XML sitemap Drupal module: https://drupal.org/project/simple_sitemap.'; const GENERATED_BY = 'Generated by the Simple XML sitemap Drupal module: https://drupal.org/project/simple_sitemap.';
const XML_VERSION = '1.0'; const XML_VERSION = '1.0';
const ENCODING = 'UTF-8'; const ENCODING = 'UTF-8';
...@@ -53,6 +57,11 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S ...@@ -53,6 +57,11 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
*/ */
protected $writer; protected $writer;
/**
* @var string
*/
protected $sitemapVariant;
/** /**
* @var array * @var array
*/ */
...@@ -87,6 +96,7 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S ...@@ -87,6 +96,7 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
$this->languageManager = $language_manager; $this->languageManager = $language_manager;
$this->time = $time; $this->time = $time;
$this->writer = $sitemap_writer; $this->writer = $sitemap_writer;
$this->sitemapVariant = self::DEFAULT_SITEMAP_VARIANT;
} }
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
...@@ -102,6 +112,15 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S ...@@ -102,6 +112,15 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
); );
} }
/**
* @param $sitemap_variant
* @return $this
*/
public function setSitemapVariant($sitemap_variant) {
$this->sitemapVariant = $sitemap_variant;
return $this;
}
/** /**
* @param array $links * @param array $links
* @return string * @return string
...@@ -111,7 +130,7 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S ...@@ -111,7 +130,7 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
protected function getChunkInfo() { protected function getChunkInfo() {
return $this->db->select('simple_sitemap', 's') return $this->db->select('simple_sitemap', 's')
->fields('s', ['delta', 'sitemap_created', 'type']) ->fields('s', ['delta', 'sitemap_created', 'type'])
->condition('s.type', $this->getPluginId()) ->condition('s.type', $this->sitemapVariant)
->condition('s.delta', self::INDEX_DELTA, '<>') ->condition('s.delta', self::INDEX_DELTA, '<>')
->execute() ->execute()
->fetchAllAssoc('delta'); ->fetchAllAssoc('delta');
...@@ -130,8 +149,10 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S ...@@ -130,8 +149,10 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
$this->writer->startElement('sitemapindex'); $this->writer->startElement('sitemapindex');
// Add attributes to document. // Add attributes to document.
$this->moduleHandler->alter('simple_sitemap_index_attributes', self::$indexAttributes); $attributes = self::$indexAttributes;
foreach (self::$indexAttributes as $name => $value) { $sitemap_variant = $this->sitemapVariant;
$this->moduleHandler->alter('simple_sitemap_index_attributes', $attributes, $sitemap_variant);
foreach ($attributes as $name => $value) {
$this->writer->writeAttribute($name, $value); $this->writer->writeAttribute($name, $value);
} }
...@@ -155,7 +176,7 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S ...@@ -155,7 +176,7 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
*/ */
public function remove() { public function remove() {
$this->db->delete('simple_sitemap') $this->db->delete('simple_sitemap')
->condition('type', $this->getPluginId()) ->condition('type', $this->sitemapVariant)
->execute(); ->execute();
return $this; return $this;
} }
...@@ -169,13 +190,13 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S ...@@ -169,13 +190,13 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
*/ */
public function generate(array $links) { public function generate(array $links) {
$highest_id = $this->db->query('SELECT MAX(id) FROM {simple_sitemap}')->fetchField(); $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', [':type' => $this->getPluginId()]) $highest_delta = $this->db->query('SELECT MAX(delta) FROM {simple_sitemap} WHERE type = :type', [':type' => $this->sitemapVariant])
->fetchField(); ->fetchField();
$values = [ $values = [
'id' => NULL === $highest_id ? 0 : $highest_id + 1, 'id' => NULL === $highest_id ? 0 : $highest_id + 1,
'delta' => NULL === $highest_delta ? self::FIRST_CHUNK_DELTA : $highest_delta + 1, 'delta' => NULL === $highest_delta ? self::FIRST_CHUNK_DELTA : $highest_delta + 1,
'type' => $this->getPluginId(), 'type' => $this->sitemapVariant,
'sitemap_string' => $this->getXml($links), 'sitemap_string' => $this->getXml($links),
'sitemap_created' => $this->time->getRequestTime(), 'sitemap_created' => $this->time->getRequestTime(),
]; ];
...@@ -183,21 +204,24 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S ...@@ -183,21 +204,24 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
$this->db->insert('simple_sitemap')->fields($values)->execute(); $this->db->insert('simple_sitemap')->fields($values)->execute();
} }