You are here

public function BatchTrait::batchGenerateSitemap in Simple XML sitemap 8.3

Same name and namespace in other branches
  1. 4.x 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 23

Class

BatchTrait

Namespace

Drupal\simple_sitemap\Queue

Code

public function batchGenerateSitemap($from = self::GENERATE_TYPE_FORM, $variants = NULL) {
  $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;
}