Commit c37d97dc authored by gbyte.co's avatar gbyte.co

Implement removeSitemap API method and enforce data integrity when using new API methods

parent f105e99e
......@@ -299,6 +299,16 @@ class Simplesitemap {
*/
public function removeSitemapTypeDefinition($name) {
if ($name !== self::DEFAULT_SITEMAP_TYPE) {
// Remove variants tied to this definition.
$variants = $this->getSitemapVariants();
foreach ($variants as $variant_name => $variant_definition) {
if ($variant_definition['type'] === $name) {
$this->removeSitemapVariant($variant_name);
}
}
// Remove type definition from configuration.
$this->configFactory->getEditable("simple_sitemap.types.$name")->delete();
}
else {
......@@ -326,7 +336,7 @@ class Simplesitemap {
* @todo document
* @todo exceptions
*/
public function addSitemapVariant($name, $definition) {
public function addSitemapVariant($name, $definition = []) {
if (empty($definition['label'])) {
$definition['label'] = $name;
}
......@@ -349,6 +359,11 @@ class Simplesitemap {
* @todo document
*/
public function removeSitemapVariant($name) {
// Remove the sitemap variant instance from database.
$this->removeSitemap($name);
// Remove the variant definition from configuration.
$variants = $this->getSitemapVariants();
if (isset($variants[$name])) {
unset($variants[$name]);
......@@ -359,6 +374,37 @@ class Simplesitemap {
return $this;
}
/**
* @param null $variants
* @return $this
*
* @todo test
*/
public function removeSitemap($variants = NULL) {
$variant_definitions = $this->getSitemapVariants();
$remove_variants = [];
if (NULL === $variants) {
$remove_variants = $variant_definitions;
}
else {
foreach ((array) $variants as $variant) {
if (isset($variant_definitions[$variant])) {
$remove_variants[$variant] = $variant_definitions[$variant];
}
}
}
if (!empty($remove_variants)) {
$type_definitions = $this->getSitemapTypeDefinitions();
foreach ($remove_variants as $variant_name => $variant_definition) {
$this->sitemapGeneratorManager
->createInstance($type_definitions[$variant_definition['type']]['sitemap_generator'])
->setSitemapVariant($variant_name)
->remove();
}
}
return $this;
}
/**
* Generates the XML sitemap and saves it to the database.
*
......@@ -452,16 +498,6 @@ class Simplesitemap {
return $from === 'nobatch' ? $this : (isset($success) ? $success : FALSE);
}
/**
* @param null $variant
* @return $this
*
* @todo implement
*/
public function removeSitemap($variant = NULL) {
return $this;
}
/**
* Returns a 'time ago' string of last timestamp generation.
*
......
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