Commit 9ec6d36f authored by gbyte's avatar gbyte Committed by Pawel G

Issue #3086749 by alex0412, gbyte.co: Drush regeneration on a per variant basis

parent 7729461a
......@@ -10,14 +10,14 @@
*/
function simple_sitemap_drush_command() {
$items['simple-sitemap-generate'] = [
'description' => 'Regenerate the XML sitemaps according to the module settings.',
'description' => 'Regenerate all XML sitemap variants or continue generation.',
'callback' => 'drush_simple_sitemap_generate',
'drupal dependencies' => ['simple_sitemap'],
'aliases' => ['ssg'],
];
$items['simple-sitemap-rebuild-queue'] = [
'description' => 'Rebuild the sitemap queue for all sitemap variants.',
'description' => 'Queue all sitemap variants for regeneration.',
'callback' => 'drush_simple_sitemap_rebuild_queue',
'drupal dependencies' => ['simple_sitemap'],
'aliases' => ['ssr'],
......
......@@ -25,12 +25,12 @@ class SimplesitemapCommands extends DrushCommands {
}
/**
* Regenerate the XML sitemaps according to the module settings.
* Regenerate all XML sitemap variants or continue generation.
*
* @command simple-sitemap:generate
*
* @usage drush simple-sitemap:generate
* Regenerate the XML sitemaps according to the module settings.
* Regenerate all XML sitemap variants or continue generation.
*
* @validate-module-enabled simple_sitemap
*
......@@ -41,19 +41,41 @@ class SimplesitemapCommands extends DrushCommands {
}
/**
* Rebuild the sitemap queue for all sitemap variants.
* Queue all or specific sitemap variants for regeneration.
*
* @command simple-sitemap:rebuild-queue
*
* @option variants
* Queue all or specific sitemap variants for regeneration.
*
* @usage drush simple-sitemap:rebuild-queue
* Rebuild the sitemap queue for all sitemap variants.
* @usage drush simple-sitemap:rebuild-queue --variants=default,test
* Rebuild the sitemap queue queuing only variants 'default' and 'test'.
*
* @validate-module-enabled simple_sitemap
*
* @aliases ssr, simple-sitemap-rebuild-queue
*
* @param array $options
*
* @throws \Drupal\Component\Plugin\Exception\PluginException
*/
public function rebuildQueue() {
$this->generator->rebuildQueue();
}
public function rebuildQueue(array $options = ['variants' => '']) {
$variants = array_keys($this->generator->getSitemapManager()->getSitemapVariants(NULL, FALSE));
if (strlen($options['variants']) > 0) {
$chosen_variants = array_map('trim', array_filter(explode(',', $options['variants'])));
if (!empty($erroneous_variants = array_diff($chosen_variants, $variants))) {
$message = "The following variants do not exist: " . implode(', ', $erroneous_variants)
. ". Available variants are: " . implode(', ', $variants) . '.';
$this->logger()->log('error', $message);
return;
}
$variants = $chosen_variants;
}
$this->generator->setVariants($variants)->rebuildQueue();
$this->logger()->log('status', 'The following variants have been queued for regeneration: ' . implode(', ', $variants) . '.');
}
}
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