You are here

class FeedRefresh in Feeds 8.3

A queue worker for importing feeds.

Plugin annotation


@QueueWorker(
  id = "feeds_feed_refresh",
  title = @Translation("Feed refresh"),
  cron = {"time" = 60},
  deriver = "Drupal\feeds\Plugin\Derivative\FeedQueueWorker"
)

Hierarchy

Expanded class hierarchy of FeedRefresh

1 file declares its use of FeedRefresh
FeedRefreshTest.php in tests/src/Unit/Plugin/QueueWorker/FeedRefreshTest.php

File

src/Plugin/QueueWorker/FeedRefresh.php, line 18

Namespace

Drupal\feeds\Plugin\QueueWorker
View source
class FeedRefresh extends FeedQueueWorkerBase {

  /**
   * {@inheritdoc}
   */
  public function processItem($data) {
    list($feed, $stage, $params) = $data;
    if (!$feed instanceof FeedInterface) {
      return;
    }

    // Check if the feed still exists.
    if (!$this
      ->feedExists($feed)) {

      // The feed in question has been deleted. Abort.
      return;
    }
    $this
      ->getExecutable()
      ->processItem($feed, $stage, $params);
  }

  /**
   * Returns Feeds executable.
   *
   * @return \Drupal\feed\FeedsExecutableInterface
   *   A feeds executable.
   */
  protected function getExecutable() {
    return \Drupal::service('class_resolver')
      ->getInstanceFromDefinition(FeedsQueueExecutable::class);
  }

  /**
   * Returns if a feed entity still exists or not.
   *
   * @param \Drupal\feeds\FeedInterface $feed
   *   The feed entity to check for existance in the database.
   *
   * @return bool
   *   True if the feed still exists, false otherwise.
   */
  protected function feedExists(FeedInterface $feed) {

    // Check if the feed still exists.
    $result = $this->entityTypeManager
      ->getStorage($feed
      ->getEntityTypeId())
      ->getQuery()
      ->condition('fid', $feed
      ->id())
      ->execute();
    if (empty($result)) {

      // The feed in question has been deleted.
      return FALSE;
    }
    return TRUE;
  }

}

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
FeedRefresh::feedExists protected function Returns if a feed entity still exists or not.
FeedRefresh::getExecutable protected function Returns Feeds executable.
FeedRefresh::processItem public function Works on a single queue item. Overrides QueueWorkerInterface::processItem
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.