You are here

public function ProcessorBase::postProcess in Feeds 8.3

Called after an import is completed.

Parameters

\Drupal\feeds\FeedInterface $feed: The feed.

\Drupal\feeds\StateInterface $state: The state object.

Overrides ProcessorInterface::postProcess

File

src/Feeds/Processor/ProcessorBase.php, line 18

Class

ProcessorBase
Defines a base processor plugin class.

Namespace

Drupal\feeds\Feeds\Processor

Code

public function postProcess(FeedInterface $feed, StateInterface $state) {
  $tokens = [
    '@feed' => $feed
      ->label(),
    '@item' => $this
      ->getItemLabel(),
    '@items' => $this
      ->getItemLabelPlural(),
  ];
  if ($state->created) {
    $state
      ->setMessage($this
      ->formatPlural($state->created, '@feed: Created @count @item.', '@feed: Created @count @items.', $tokens));
  }
  if ($state->updated) {
    $state
      ->setMessage($this
      ->formatPlural($state->updated, '@feed: Updated @count @item.', '@feed: Updated @count @items.', $tokens));
  }
  if ($state->failed) {
    $state
      ->setMessage($this
      ->formatPlural($state->failed, '@feed: Failed importing @count @item.', '@feed: Failed importing @count @items.', $tokens), 'error');
  }
  if (!$state->created && !$state->updated && !$state->failed) {
    $state
      ->setMessage($this
      ->t('@feed: There are no new @items.', $tokens));
  }

  // Find out how many items were cleaned.
  $clean_state = $feed
    ->getState(StateInterface::CLEAN);
  if ($clean_state->updated) {
    $clean_state
      ->setMessage($this
      ->formatPlural($clean_state->updated, '@feed: Cleaned @count @item.', '@feed: Cleaned @count @items.', $tokens));
  }
}