You are here

class FeedsBatchBatch in Feeds 8.3

A batch task for the batch API.

Hierarchy

Expanded class hierarchy of FeedsBatchBatch

File

src/FeedsBatchBatch.php, line 10

Namespace

Drupal\feeds
View source
class FeedsBatchBatch extends FeedsBatchBase {
  use StringTranslationTrait;

  /**
   * Adds a new batch.
   *
   * @param array $batch_definition
   *   An associative array defining the batch.
   */
  protected function batchSet(array $batch_definition) {
    return batch_set($batch_definition);
  }

  /**
   * {@inheritdoc}
   */
  public function run() {
    $batch = [
      'title' => '',
      'operations' => [],
    ];
    foreach ($this->operations as $operation) {
      $batch['operations'][] = [
        [
          $this->executable,
          'processItem',
        ],
        [
          $this->feed,
          $operation['stage'],
          $operation['params'],
        ],
      ];
    }
    switch ($this->stage) {
      case FeedsExecutableInterface::FETCH:
        $batch['title'] = $this
          ->t('Fetching: %title', [
          '%title' => $this->feed
            ->label(),
        ]);
        $batch['error_message'] = $this
          ->t('An error occurred while fetching %title.', [
          '%title' => $this->feed
            ->label(),
        ]);
        break;
      case FeedsExecutableInterface::PARSE:
        $batch['title'] = $this
          ->t('Parsing: %title', [
          '%title' => $this->feed
            ->label(),
        ]);
        $batch['error_message'] = $this
          ->t('An error occurred while parsing %title.', [
          '%title' => $this->feed
            ->label(),
        ]);
        break;
      case FeedsExecutableInterface::PROCESS:
        $batch['title'] = $this
          ->t('Processing: %title', [
          '%title' => $this->feed
            ->label(),
        ]);
        $batch['error_message'] = $this
          ->t('An error occurred while processing %title.', [
          '%title' => $this->feed
            ->label(),
        ]);
        break;
      case FeedsExecutableInterface::CLEAN:
        $batch['title'] = $this
          ->t('Cleaning: %title', [
          '%title' => $this->feed
            ->label(),
        ]);
        $batch['error_message'] = $this
          ->t('An error occurred while cleaning %title.', [
          '%title' => $this->feed
            ->label(),
        ]);
        break;
    }
    $batch += [
      'init_message' => $batch['title'],
      'progress_message' => $batch['title'],
    ];
    $this
      ->batchSet($batch);
    return $this;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FeedsBatchBase::$executable protected property The Feeds executable.
FeedsBatchBase::$feed protected property The feed to run a batch for.
FeedsBatchBase::$operations protected property A list of operations to run.
FeedsBatchBase::$stage protected property The stage of the batch to run.
FeedsBatchBase::addOperation public function Adds an operation. Overrides FeedsBatchInterface::addOperation
FeedsBatchBase::__construct public function Constructs a new FeedsBatchBase object. 1
FeedsBatchBatch::batchSet protected function Adds a new batch.
FeedsBatchBatch::run public function Runs the batch. Overrides FeedsBatchInterface::run
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.