Commit 1119396a authored by gbyte.co's avatar gbyte.co

Fix variant deletion on queue rebuild

parent 65a5da69
...@@ -184,6 +184,7 @@ class QueueWorker { ...@@ -184,6 +184,7 @@ class QueueWorker {
$this->getQueuedElementCount(TRUE); $this->getQueuedElementCount(TRUE);
// todo: May not be clean to remove sitemap variants data when queuing elements. // todo: May not be clean to remove sitemap variants data when queuing elements.
// todo: Add test.
// Remove all sitemap variant instances where no results have been queued. // Remove all sitemap variant instances where no results have been queued.
$this->manager->removeSitemap(array_keys(array_filter($sitemap_variants, function($e) { return empty($e['data']); }))); $this->manager->removeSitemap(array_keys(array_filter($sitemap_variants, function($e) { return empty($e['data']); })));
......
...@@ -164,10 +164,9 @@ class SimplesitemapManager { ...@@ -164,10 +164,9 @@ class SimplesitemapManager {
/** /**
* @param $name * @param $name
* @param $definition * @param array $definition
* @return $this * @return $this
* * @throws \Drupal\Component\Plugin\Exception\PluginException
* @todo document
*/ */
public function addSitemapVariant($name, $definition = []) { public function addSitemapVariant($name, $definition = []) {
$all_variants = $this->getSitemapVariants(); $all_variants = $this->getSitemapVariants();
...@@ -209,24 +208,42 @@ class SimplesitemapManager { ...@@ -209,24 +208,42 @@ class SimplesitemapManager {
return $this; return $this;
} }
/**
* @param null|array|string $variant_names
* null: Removes all sitemap instances
* string|array: Removes specific instances
*
* @return $this
* @throws \Drupal\Component\Plugin\Exception\PluginException
*/
public function removeSitemap($variant_names = NULL) { public function removeSitemap($variant_names = NULL) {
$saved_variants = $this->getSitemapVariants(); if (NULL === $variant_names || !empty((array) $variant_names)) {
$remove_variants = NULL !== $variant_names && !empty((array) $variant_names) $saved_variants = $this->getSitemapVariants();
? array_intersect_key($saved_variants, array_flip((array) $variant_names)) $remove_variants = NULL === $variant_names
: $saved_variants; ? $saved_variants
: array_intersect_key($saved_variants, array_flip((array) $variant_names));
if (!empty($remove_variants)) {
$type_definitions = $this->getSitemapTypes(); if (!empty($remove_variants)) {
foreach ($remove_variants as $variant_name => $variant_definition) { $type_definitions = $this->getSitemapTypes();
$this->getSitemapGenerator($type_definitions[$variant_definition['type']]['sitemapGenerator']) foreach ($remove_variants as $variant_name => $variant_definition) {
->setSitemapVariant($variant_name) $this->getSitemapGenerator($type_definitions[$variant_definition['type']]['sitemapGenerator'])
->remove(); ->setSitemapVariant($variant_name)
->remove();
}
} }
} }
return $this; return $this;
} }
/**
* @param null|array|string $variant_names
* null: Removes all sitemap variants
* string|array: Removes specific variants
*
* @return $this
* @throws \Drupal\Component\Plugin\Exception\PluginException
*/
public function removeSitemapVariants($variant_names = NULL) { public function removeSitemapVariants($variant_names = NULL) {
if (NULL === $variant_names || !empty((array) $variant_names)) { if (NULL === $variant_names || !empty((array) $variant_names)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment