You are here

public function SimplesitemapCommands::rebuildQueue in Simple XML sitemap 8.3

Same name and namespace in other branches
  1. 4.x src/Commands/SimpleSitemapCommands.php \Drupal\simple_sitemap\Commands\SimpleSitemapCommands::rebuildQueue()

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

Parameters

array $options:

Throws

\Drupal\Component\Plugin\Exception\PluginException

File

src/Commands/SimplesitemapCommands.php, line 65

Class

SimplesitemapCommands
Class SimplesitemapCommands @package Drupal\simple_sitemap\Commands

Namespace

Drupal\simple_sitemap\Commands

Code

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('notice', 'The following variants have been queued for regeneration: ' . implode(', ', $variants) . '.');
}