You are here

abstract class FeedQueueWorkerBase in Feeds 8.3

Base class for Feed queue workers.

Hierarchy

Expanded class hierarchy of FeedQueueWorkerBase

File

src/Plugin/QueueWorker/FeedQueueWorkerBase.php, line 20

Namespace

Drupal\feeds\Plugin\QueueWorker
View source
abstract class FeedQueueWorkerBase extends QueueWorkerBase implements ContainerFactoryPluginInterface {
  use EventDispatcherTrait;

  /**
   * The account switcher.
   *
   * @var \Drupal\Core\Session\AccountSwitcherInterface
   */
  protected $accountSwitcher;

  /**
   * The queue factory.
   *
   * @var \Drupal\Core\Queue\QueueFactory
   */
  protected $queueFactory;

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Constructs a FeedQueueWorkerBase object.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param array $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Queue\QueueFactory $queue_factory
   *   The queue factory.
   * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
   *   The event dispatcher.
   * @param \Drupal\Core\Session\AccountSwitcherInterface $account_switcher
   *   The account switcher.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(array $configuration, $plugin_id, array $plugin_definition, QueueFactory $queue_factory, EventDispatcherInterface $event_dispatcher, AccountSwitcherInterface $account_switcher, EntityTypeManagerInterface $entity_type_manager) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->queueFactory = $queue_factory;
    $this
      ->setEventDispatcher($event_dispatcher);
    $this->accountSwitcher = $account_switcher;
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('queue'), $container
      ->get('event_dispatcher'), $container
      ->get('account_switcher'), $container
      ->get('entity_type.manager'));
  }

  /**
   * Handles an import exception.
   */
  protected function handleException(FeedInterface $feed, \Exception $exception) {
    $feed
      ->finishImport();
    if (!$exception instanceof EmptyFeedException) {
      throw $exception;
    }
  }

  /**
   * Safely switches to another account.
   *
   * @param \Drupal\feeds\FeedInterface $feed
   *   The feed that has the account to switch to.
   *
   * @return \Drupal\Core\Session\AccountSwitcherInterface
   *   The account switcher to call switchBack() on.
   *
   * @see \Drupal\Core\Session\AccountSwitcherInterface::switchTo()
   */
  protected function switchAccount(FeedInterface $feed) {
    $account = new AccountProxy($this
      ->getEventDispatcher());
    $account
      ->setInitialAccountId($feed
      ->getOwnerId());
    return $this->accountSwitcher
      ->switchTo($account);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EventDispatcherTrait::$_eventDispatcher private property The event dispatcher service.
EventDispatcherTrait::dispatchEvent protected function Dispatches an event.
EventDispatcherTrait::getEventDispatcher protected function Returns the event dispatcher service.
EventDispatcherTrait::setEventDispatcher public function Sets the event dispatcher service to use.
FeedQueueWorkerBase::$accountSwitcher protected property The account switcher.
FeedQueueWorkerBase::$entityTypeManager protected property The entity type manager.
FeedQueueWorkerBase::$queueFactory protected property The queue factory.
FeedQueueWorkerBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
FeedQueueWorkerBase::handleException protected function Handles an import exception.
FeedQueueWorkerBase::switchAccount protected function Safely switches to another account.
FeedQueueWorkerBase::__construct public function Constructs a FeedQueueWorkerBase object. Overrides PluginBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
QueueWorkerInterface::processItem public function Works on a single queue item. 6