You are here

class State in Feeds 8.3

Status of the import or clearing operation of a Feed.

Hierarchy

Expanded class hierarchy of State

11 files declare their use of State
CleanState.php in src/Feeds/State/CleanState.php
CsvParserTest.php in tests/src/Unit/Feeds/Parser/CsvParserTest.php
DirectoryFetcherTest.php in tests/src/Unit/Feeds/Fetcher/DirectoryFetcherTest.php
EntityProcessorBaseTest.php in tests/src/Kernel/Feeds/Processor/EntityProcessorBaseTest.php
Feed.php in src/Entity/Feed.php

... See full list

File

src/State.php, line 8

Namespace

Drupal\feeds
View source
class State implements StateInterface {

  /**
   * Denotes the progress made.
   *
   * 0.0 meaning no progress. 1.0 = StateInterface::BATCH_COMPLETE meaning
   * finished.
   *
   * @var float
   */
  public $progress = StateInterface::BATCH_COMPLETE;

  /**
   * Used as a pointer to store where left off. Must be serializable.
   *
   * @var scalar
   */
  public $pointer;

  /**
   * The total number of items being processed.
   *
   * @var int
   */
  public $total = 0;

  /**
   * The number of Feed items created.
   *
   * @var int
   */
  public $created = 0;

  /**
   * The number of Feed items updated.
   *
   * @var int
   */
  public $updated = 0;

  /**
   * The number of Feed items deleted.
   *
   * @var int
   */
  public $deleted = 0;

  /**
   * The number of Feed items skipped.
   *
   * @var int
   */
  public $skipped = 0;

  /**
   * The number of failed Feed items.
   *
   * @var int
   */
  public $failed = 0;

  /**
   * The list of messages to display to the user.
   *
   * Each entry on the array is expected to have the following values:
   * - message (string|\Drupal\Component\Render\MarkupInterface): the translated
   *   message to be displayed to the user;
   * - type (string): the message's type. These values are supported:
   *   - 'status'
   *   - 'warning'
   *   - 'error'
   * - repeat (bool): whether or not showing the same message more than once.
   *
   * @var array
   */
  protected $messages = [];

  /**
   * {@inheritdoc}
   */
  public function progress($total, $progress) {
    if ($progress > $total || $total === $progress) {
      $this
        ->setCompleted();
    }
    elseif ($total) {
      $this->progress = (double) ($progress / $total);
      if ($this->progress === StateInterface::BATCH_COMPLETE && $total !== $progress) {
        $this->progress = 0.99;
      }
    }
    else {
      $this
        ->setCompleted();
    }
  }

  /**
   * {@inheritdoc}
   */
  public function setCompleted() {
    $this->progress = StateInterface::BATCH_COMPLETE;
  }

  /**
   * {@inheritdoc}
   */
  public function setMessage($message = NULL, $type = 'status', $repeat = FALSE) {
    $this->messages[] = [
      'message' => $message,
      'type' => $type,
      'repeat' => $repeat,
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function displayMessages() {
    foreach ($this->messages as $message) {
      \Drupal::messenger()
        ->addMessage($message['message'], $message['type'], $message['repeat']);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function logMessages(FeedInterface $feed) {
    foreach ($this->messages as $message) {
      switch ($message['type']) {
        case 'status':
          $message['type'] = 'info';
          break;
      }
      \Drupal::logger('feeds')
        ->log($message['type'], $message['message'], [
        'feed' => $feed,
      ]);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
State::$created public property The number of Feed items created.
State::$deleted public property The number of Feed items deleted.
State::$failed public property The number of failed Feed items.
State::$messages protected property The list of messages to display to the user.
State::$pointer public property Used as a pointer to store where left off. Must be serializable.
State::$progress public property Denotes the progress made. 1
State::$skipped public property The number of Feed items skipped.
State::$total public property The total number of items being processed.
State::$updated public property The number of Feed items updated.
State::displayMessages public function Shows the messages to the user. Overrides StateInterface::displayMessages
State::logMessages public function Logs all messages. Overrides StateInterface::logMessages
State::progress public function Reports the progress of a batch. Overrides StateInterface::progress 1
State::setCompleted public function Immediately completes the batch. Overrides StateInterface::setCompleted
State::setMessage public function Sets a message to display to the user. Overrides StateInterface::setMessage
StateInterface::BATCH_COMPLETE constant Batch operation complete.
StateInterface::CLEAN constant Denotes the clean stage.
StateInterface::CLEAR constant Denotes the clear stage.
StateInterface::EXPIRE constant Denotes the expire stage.
StateInterface::FETCH constant Denotes the fetch stage.
StateInterface::PARSE constant Denotes the parse stage.
StateInterface::PROCESS constant Denotes the process stage.
StateInterface::START constant The start time key.