You are here

public function BatchTrait::batchGenerateSitemap in Simple XML sitemap 4.x

Same name and namespace in other branches
  1. 8.3 src/Queue/BatchTrait.php \Drupal\simple_sitemap\Queue\BatchTrait::batchGenerateSitemap()

Parameters

string $from:

array|null $variants:

Return value

bool

File

src/Queue/BatchTrait.php, line 24

Class

BatchTrait

Namespace

Drupal\simple_sitemap\Queue

Code

public function batchGenerateSitemap(string $from = self::GENERATE_TYPE_FORM, ?array $variants = NULL) : bool {
  $this->batch = [
    'title' => $this
      ->t('Generating XML sitemaps'),
    'init_message' => $this
      ->t('Initializing...'),
    'error_message' => $this
      ->t(self::$batchErrorMessage),
    'progress_message' => $this
      ->t('Processing items from the queue.<br>Each sitemap variant gets published after all of its items have been processed.'),
    'operations' => [
      [
        __CLASS__ . '::' . 'doBatchGenerateSitemap',
        [],
      ],
    ],
    'finished' => [
      __CLASS__,
      'finishGeneration',
    ],
  ];
  switch ($from) {
    case self::GENERATE_TYPE_FORM:

      // Start batch process.
      batch_set($this->batch);
      return TRUE;
    case self::GENERATE_TYPE_DRUSH:

      // Start drush batch process.
      batch_set($this->batch);

      // See https://www.drupal.org/node/638712
      $this->batch =& batch_get();
      $this->batch['progressive'] = FALSE;
      drush_backend_batch_process();
      return TRUE;
  }
  return FALSE;
}