You are here

class BrightcoveVideoQueueWorker in Brightcove Video Connect 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/QueueWorker/BrightcoveVideoQueueWorker.php \Drupal\brightcove\Plugin\QueueWorker\BrightcoveVideoQueueWorker
  2. 3.x src/Plugin/QueueWorker/BrightcoveVideoQueueWorker.php \Drupal\brightcove\Plugin\QueueWorker\BrightcoveVideoQueueWorker

Processes Entity Update Tasks for Video.

Plugin annotation


@QueueWorker(
  id = "brightcove_video_queue_worker",
  title = @Translation("Brightcove video queue worker."),
  cron = { "time" = 30 }
)

Hierarchy

Expanded class hierarchy of BrightcoveVideoQueueWorker

File

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

Namespace

Drupal\brightcove\Plugin\QueueWorker
View source
class BrightcoveVideoQueueWorker extends QueueWorkerBase implements ContainerFactoryPluginInterface {

  /**
   * The brightcove_video storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $storage;

  /**
   * Entity query factory.
   *
   * @var \Drupal\Core\Database\Connection
   */
  protected $connection;

  /**
   * The playlist page queue object.
   *
   * @var \Drupal\Core\Queue\QueueInterface
   */
  protected $textTrackQueue;

  /**
   * The playlist page queue object.
   *
   * @var \Drupal\Core\Queue\QueueInterface
   */
  protected $textTrackDeleteQueue;

  /**
   * Constructs a new BrightcoveVideoQueueWorker 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\Entity\EntityStorageInterface $storage
   *   The storage object.
   * @param \Drupal\Core\Database\Connection $connection
   *   Database connection.
   * @param \Drupal\Core\Queue\QueueInterface $text_track_queue
   *   Text track queue object.
   * @param \Drupal\Core\Queue\QueueInterface $text_track_delete_queue
   *   Text track delete queue object.
   */
  public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityStorageInterface $storage, Connection $connection, QueueInterface $text_track_queue, QueueInterface $text_track_delete_queue) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->storage = $storage;
    $this->connection = $connection;
    $this->textTrackQueue = $text_track_queue;
    $this->textTrackDeleteQueue = $text_track_delete_queue;
  }

  /**
   * {@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')
      ->getStorage('brightcove_video'), $container
      ->get('database'), $container
      ->get('queue')
      ->get('brightcove_text_track_queue_worker'), $container
      ->get('queue')
      ->get('brightcove_text_track_delete_queue_worker'));
  }

  /**
   * {@inheritdoc}
   */
  public function processItem($data) {

    /** @var \Brightcove\Item\Video\Video $video */
    $video = $data['video'];

    /** @var \Drupal\brightcove\Entity\BrightcoveVideo $video_entity */
    $video_entity = BrightcoveVideo::createOrUpdate($video, $this->storage, $data['api_client_id']);
    if (!empty($video_entity)) {

      // Get existing text tracks.
      $existing_text_tracks = [];
      foreach ($video_entity
        ->getTextTracks() as $text_track) {

        /** @var \Drupal\brightcove\Entity\BrightcoveTextTrack $text_track_entity */
        $text_track_entity = BrightcoveTextTrack::load($text_track['target_id']);
        if (!is_null($text_track_entity)) {
          $existing_text_tracks[$text_track_entity
            ->getTextTrackId()] = TRUE;
        }
      }

      // Save Video text tracks.
      $text_tracks = $video
        ->getTextTracks();
      foreach ($text_tracks as $text_track) {

        // Remove existing text tracks from the list which are still existing on
        // Brightcove.
        if (isset($existing_text_tracks[$text_track
          ->getId()])) {
          unset($existing_text_tracks[$text_track
            ->getId()]);
        }

        // Create new queue item for text track.
        $this->textTrackQueue
          ->createItem([
          'text_track' => $text_track,
          'video_entity_id' => $video_entity
            ->id(),
        ]);
      }

      // Remove existing text tracks which are no longer available on
      // Brightcove.
      foreach (array_keys($existing_text_tracks) as $text_track_id) {

        // Create new delete queue item for text track.
        $this->textTrackDeleteQueue
          ->createItem($text_track_id);
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BrightcoveVideoQueueWorker::$connection protected property Entity query factory.
BrightcoveVideoQueueWorker::$storage protected property The brightcove_video storage.
BrightcoveVideoQueueWorker::$textTrackDeleteQueue protected property The playlist page queue object.
BrightcoveVideoQueueWorker::$textTrackQueue protected property The playlist page queue object.
BrightcoveVideoQueueWorker::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
BrightcoveVideoQueueWorker::processItem public function Works on a single queue item. Overrides QueueWorkerInterface::processItem
BrightcoveVideoQueueWorker::__construct public function Constructs a new BrightcoveVideoQueueWorker 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.