Commit 1119396a authored by Pawel G's avatar Pawel G

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,11 +208,20 @@ class SimplesitemapManager { ...@@ -209,11 +208,20 @@ 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) {
if (NULL === $variant_names || !empty((array) $variant_names)) {
$saved_variants = $this->getSitemapVariants(); $saved_variants = $this->getSitemapVariants();
$remove_variants = NULL !== $variant_names && !empty((array) $variant_names) $remove_variants = NULL === $variant_names
? array_intersect_key($saved_variants, array_flip((array) $variant_names)) ? $saved_variants
: $saved_variants; : array_intersect_key($saved_variants, array_flip((array) $variant_names));
if (!empty($remove_variants)) { if (!empty($remove_variants)) {
$type_definitions = $this->getSitemapTypes(); $type_definitions = $this->getSitemapTypes();
...@@ -223,10 +231,19 @@ class SimplesitemapManager { ...@@ -223,10 +231,19 @@ class SimplesitemapManager {
->remove(); ->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