BrightcovePlaylistQueueWorker.php in Brightcove Video Connect 8
File
src/Plugin/QueueWorker/BrightcovePlaylistQueueWorker.php
View source
<?php
namespace Drupal\brightcove\Plugin\QueueWorker;
use Drupal\brightcove\Entity\BrightcovePlaylist;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\QueueWorkerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Queue\RequeueException;
class BrightcovePlaylistQueueWorker extends QueueWorkerBase implements ContainerFactoryPluginInterface {
protected $playlistStorage;
protected $videoStorage;
public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityStorageInterface $playlist_storage, EntityStorageInterface $video_storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->playlistStorage = $playlist_storage;
$this->videoStorage = $video_storage;
}
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_playlist'), $container
->get('entity_type.manager')
->getStorage('brightcove_video'));
}
public function processItem($data) {
$playlist = $data['playlist'];
try {
BrightcovePlaylist::createOrUpdate($playlist, $this->playlistStorage, $this->videoStorage, $data['api_client_id']);
} catch (\Exception $e) {
throw new RequeueException($e
->getMessage(), $e
->getCode(), $e);
}
}
}