FeedQueueWorkerBase.php in Feeds 8.3
File
src/Plugin/QueueWorker/FeedQueueWorkerBase.php
View source
<?php
namespace Drupal\feeds\Plugin\QueueWorker;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\QueueFactory;
use Drupal\Core\Queue\QueueWorkerBase;
use Drupal\Core\Session\AccountProxy;
use Drupal\Core\Session\AccountSwitcherInterface;
use Drupal\feeds\Event\EventDispatcherTrait;
use Drupal\feeds\Exception\EmptyFeedException;
use Drupal\feeds\FeedInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
abstract class FeedQueueWorkerBase extends QueueWorkerBase implements ContainerFactoryPluginInterface {
use EventDispatcherTrait;
protected $accountSwitcher;
protected $queueFactory;
protected $entityTypeManager;
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;
}
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'));
}
protected function handleException(FeedInterface $feed, \Exception $exception) {
$feed
->finishImport();
if (!$exception instanceof EmptyFeedException) {
throw $exception;
}
}
protected function switchAccount(FeedInterface $feed) {
$account = new AccountProxy($this
->getEventDispatcher());
$account
->setInitialAccountId($feed
->getOwnerId());
return $this->accountSwitcher
->switchTo($account);
}
}