You are here

class ScheduledTransitionJob in Scheduled Transitions 8

Same name and namespace in other branches
  1. 2.x src/Plugin/QueueWorker/ScheduledTransitionJob.php \Drupal\scheduled_transitions\Plugin\QueueWorker\ScheduledTransitionJob

Runs a scheduled transition.

Plugin annotation


@QueueWorker(
  id = "scheduled_transition_job",
  title = @Translation("Scheduled transition job"),
  cron = {"time" = 900}
)

Hierarchy

Expanded class hierarchy of ScheduledTransitionJob

1 file declares its use of ScheduledTransitionJob
ScheduledTransitionsJobs.php in src/ScheduledTransitionsJobs.php

File

src/Plugin/QueueWorker/ScheduledTransitionJob.php, line 23

Namespace

Drupal\scheduled_transitions\Plugin\QueueWorker
View source
class ScheduledTransitionJob extends QueueWorkerBase implements ContainerFactoryPluginInterface {

  /**
   * The key in data with the ID of a scheduled transition entity to process.
   */
  const SCHEDULED_TRANSITION_ID = 'scheduled_transition_id';

  /**
   * Executes transitions.
   *
   * @var \Drupal\scheduled_transitions\ScheduledTransitionsRunnerInterface
   */
  protected $scheduledTransitionsRunner;

  /**
   * Storage for scheduled transitions.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $scheduledTransitionStorage;

  /**
   * Constructs a new ScheduledTransitionJob.
   *
   * @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\Core\Entity\EntityTypeManagerInterface $entityTypeManager
   *   The entity type manager.
   * @param \Drupal\scheduled_transitions\ScheduledTransitionsRunnerInterface $scheduledTransitionsRunner
   *   Executes transitions.
   */
  public function __construct(array $configuration, string $plugin_id, $plugin_definition, EntityTypeManagerInterface $entityTypeManager, ScheduledTransitionsRunnerInterface $scheduledTransitionsRunner) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->scheduledTransitionStorage = $entityTypeManager
      ->getStorage('scheduled_transition');
    $this->scheduledTransitionsRunner = $scheduledTransitionsRunner;
  }

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

  /**
   * {@inheritdoc}
   */
  public function processItem($data) {
    $id = $data[static::SCHEDULED_TRANSITION_ID];
    $transition = $this->scheduledTransitionStorage
      ->load($id);
    if ($transition) {
      try {
        $this->scheduledTransitionsRunner
          ->runTransition($transition);
      } catch (ScheduledTransitionMissingEntity $exception) {
        $transition
          ->delete();
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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.
ScheduledTransitionJob::$scheduledTransitionsRunner protected property Executes transitions.
ScheduledTransitionJob::$scheduledTransitionStorage protected property Storage for scheduled transitions.
ScheduledTransitionJob::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
ScheduledTransitionJob::processItem public function Works on a single queue item. Overrides QueueWorkerInterface::processItem
ScheduledTransitionJob::SCHEDULED_TRANSITION_ID constant The key in data with the ID of a scheduled transition entity to process.
ScheduledTransitionJob::__construct public function Constructs a new ScheduledTransitionJob. Overrides PluginBase::__construct