You are here

EntityShareCronPending.php in Entity Share Cron 8

File

src/Plugin/QueueWorker/EntityShareCronPending.php
View source
<?php

namespace Drupal\entity_share_cron\Plugin\QueueWorker;

use Drupal\Core\Queue\QueueWorkerBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\entity_share_cron\EntityShareCronService;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Psr\Log\LoggerInterface;

/**
 * Imports entities from Entity Share channels.
 *
 * @QueueWorker(
 *   id = "entity_share_cron_pending",
 *   title = @Translation("Entity Share Cron"),
 *   cron = {"time" = 10}
 * )
 */
class EntityShareCronPending extends QueueWorkerBase implements ContainerFactoryPluginInterface {
  const PAGE_LIMIT = 5;

  /**
   * Entity Share Cron service.
   *
   * @var \Drupal\entity_share_cron\EntityShareCronServiceInterface
   */
  protected $service;

  /**
   * Logger.
   *
   * @var \Psr\Log\LoggerInterface
   */
  protected $logger;

  /**
   * Constructor.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\entity_share_cron\EntityShareCronService $service
   *   Entity Share Cron service.
   * @param \Psr\Log\LoggerInterface $logger
   *   Logger.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityShareCronService $service, LoggerInterface $logger) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->service = $service;
    $this->logger = $logger;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('entity_share_cron'), $container
      ->get('logger.factory')
      ->get('entitiy_share_cron'));
  }

  /**
   * {@inheritdoc}
   */
  public function processItem($data) {
    $remote_id = $data['remote_id'];
    $channel_id = $data['channel_id'];
    $channel_info = $data['channel_info'];
    $this->logger
      ->info('Importing entities from channel %channel_id from remote %remote_id.', [
      '%channel_id' => $channel_id,
      '%remote_id' => $remote_id,
    ]);
    $this->service
      ->sync($remote_id, $channel_id, $channel_info, self::PAGE_LIMIT);
  }

}

Classes

Namesort descending Description
EntityShareCronPending Imports entities from Entity Share channels.