You are here

class BrightcoveVideoDeleteQueueWorker in Brightcove Video Connect 8.2

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

Processes Entity Delete Tasks for Video.

Plugin annotation


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

Hierarchy

Expanded class hierarchy of BrightcoveVideoDeleteQueueWorker

File

src/Plugin/QueueWorker/BrightcoveVideoDeleteQueueWorker.php, line 21

Namespace

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

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

  /**
   * 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
   *   Brightcove Video Entity storage.
   */
  public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityStorageInterface $storage) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->storage = $storage;
  }

  /**
   * {@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'));
  }

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

    // Check the video if it is available on Brightcove or not.
    try {
      $cms = BrightcoveUtil::getCmsApi($data->api_client);
      $cms
        ->getVideo($data->video_id);
    } catch (APIException $e) {

      // If we got a not found response, delete the local version of the video.
      if ($e
        ->getCode() == 404) {

        /** @var \Drupal\brightcove\Entity\BrightcoveVideo $video */
        $video = $this->storage
          ->load($data->bcvid);
        if (!empty($video)) {
          $video
            ->delete(TRUE);
        }
      }
      else {
        throw new APIException($e
          ->getMessage(), $e
          ->getCode(), $e, $e
          ->getResponseBody());
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BrightcoveVideoDeleteQueueWorker::$storage protected property The brightcove_video storage.
BrightcoveVideoDeleteQueueWorker::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
BrightcoveVideoDeleteQueueWorker::processItem public function Works on a single queue item. Overrides QueueWorkerInterface::processItem
BrightcoveVideoDeleteQueueWorker::__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.