Commit f484dc1d authored by Pawel G's avatar Pawel G

Remove sitemaps from DB when removing variants from configuration

parent 67de3e4b
...@@ -183,12 +183,13 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S ...@@ -183,12 +183,13 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
* @return $this * @return $this
*/ */
public function remove($mode = 'all') { public function remove($mode = 'all') {
self::removeSitemapVariant($this->sitemapVariant, $mode); self::removeSitemapVariants($this->sitemapVariant, $mode);
return $this; return $this;
} }
public static function removeSitemapVariant($variant = NULL, $mode = 'all') { public static function removeSitemapVariants($variants = NULL, $mode = 'all') {
$variants = is_array($variants) || NULL === $variants ? $variants : [$variants];
$delete_query = \Drupal::database()->delete('simple_sitemap'); $delete_query = \Drupal::database()->delete('simple_sitemap');
switch($mode) { switch($mode) {
...@@ -207,8 +208,8 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S ...@@ -207,8 +208,8 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
//todo: throw error //todo: throw error
} }
if (NULL !== $variant) { if (NULL !== $variants) {
$delete_query->condition('type', $variant); $delete_query->condition('type', $variants, 'IN');
} }
$delete_query->execute(); $delete_query->execute();
......
...@@ -110,7 +110,7 @@ class QueueWorker { ...@@ -110,7 +110,7 @@ class QueueWorker {
*/ */
public function deleteQueue() { public function deleteQueue() {
$this->queue->deleteQueue(); $this->queue->deleteQueue();
SitemapGeneratorBase::removeSitemapVariant(NULL, 'unpublished'); SitemapGeneratorBase::removeSitemapVariants(NULL, 'unpublished'); //todo should call the remove() method of every plugin instead?
$this->variantProcessedNow = NULL; $this->variantProcessedNow = NULL;
$this->generatorProcessedNow = NULL; $this->generatorProcessedNow = NULL;
$this->results = []; $this->results = [];
......
...@@ -190,7 +190,8 @@ class SimplesitemapManager { ...@@ -190,7 +190,8 @@ class SimplesitemapManager {
} }
public function removeSitemapVariants($variant_names = NULL) { public function removeSitemapVariants($variant_names = NULL) {
// $this->removeSitemap($variant_names); // todo SitemapGeneratorBase::removeSitemapVariants($variant_names); //todo should call the remove() method of every plugin instead?
if (NULL === $variant_names) { if (NULL === $variant_names) {
foreach ($this->configFactory->listAll('simple_sitemap.variants.') as $config_name) { foreach ($this->configFactory->listAll('simple_sitemap.variants.') as $config_name) {
$this->configFactory->getEditable($config_name)->delete(); $this->configFactory->getEditable($config_name)->delete();
......
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