Skip to content

Instantly share code, notes, and snippets.

@SpacemanPete
Created November 24, 2020 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SpacemanPete/e5e1782b82cea4c9e22894199f8f7f69 to your computer and use it in GitHub Desktop.
Save SpacemanPete/e5e1782b82cea4c9e22894199f8f7f69 to your computer and use it in GitHub Desktop.
Patch for drupal/brightcove module to enable folder filtering for custom enhancement module
diff --git a/src/Plugin/QueueWorker/BrightcovePlaylistQueueWorker.php b/src/Plugin/QueueWorker/BrightcovePlaylistQueueWorker.php
index 35fadb7..69dd27c 100644
--- a/src/Plugin/QueueWorker/BrightcovePlaylistQueueWorker.php
+++ b/src/Plugin/QueueWorker/BrightcovePlaylistQueueWorker.php
@@ -78,7 +78,7 @@ class BrightcovePlaylistQueueWorker extends QueueWorkerBase implements Container
BrightcovePlaylist::createOrUpdate($playlist, $this->playlistStorage, $this->videoStorage, $data['api_client_id']);
}
catch (\Exception $e) {
- throw new RequeueException($e->getMessage(), $e->getCode(), $e);
+ \Drupal::logger('brightcove_extras')->error('Playlist update error. Video does not exist locally.');
}
}
diff --git a/src/Plugin/QueueWorker/BrightcoveVideoQueueWorker.php b/src/Plugin/QueueWorker/BrightcoveVideoQueueWorker.php
index a9aa590..1296507 100644
--- a/src/Plugin/QueueWorker/BrightcoveVideoQueueWorker.php
+++ b/src/Plugin/QueueWorker/BrightcoveVideoQueueWorker.php
@@ -2,14 +2,16 @@
namespace Drupal\brightcove\Plugin\QueueWorker;
+use Brightcove\Item\Video\Video;
+use Drupal;
use Drupal\brightcove\Entity\BrightcoveTextTrack;
+use Drupal\brightcove\Entity\BrightcoveVideo;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\QueueInterface;
use Drupal\Core\Queue\QueueWorkerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
-use Drupal\brightcove\Entity\BrightcoveVideo;
/**
* Processes Entity Update Tasks for Video.
@@ -20,33 +22,34 @@ use Drupal\brightcove\Entity\BrightcoveVideo;
* cron = { "time" = 30 }
* )
*/
-class BrightcoveVideoQueueWorker extends QueueWorkerBase implements ContainerFactoryPluginInterface {
+class BrightcoveVideoQueueWorker extends QueueWorkerBase implements ContainerFactoryPluginInterface
+{
/**
* The brightcove_video storage.
*
- * @var \Drupal\Core\Entity\EntityStorageInterface
+ * @var EntityStorageInterface
*/
protected $storage;
/**
* Entity query factory.
*
- * @var \Drupal\Core\Database\Connection
+ * @var Connection
*/
protected $connection;
/**
* The playlist page queue object.
*
- * @var \Drupal\Core\Queue\QueueInterface
+ * @var QueueInterface
*/
protected $textTrackQueue;
/**
* The playlist page queue object.
*
- * @var \Drupal\Core\Queue\QueueInterface
+ * @var QueueInterface
*/
protected $textTrackDeleteQueue;
@@ -59,16 +62,17 @@ class BrightcoveVideoQueueWorker extends QueueWorkerBase implements ContainerFac
* The plugin_id for the plugin instance.
* @param array $plugin_definition
* The plugin implementation definition.
- * @param \Drupal\Core\Entity\EntityStorageInterface $storage
+ * @param EntityStorageInterface $storage
* The storage object.
- * @param \Drupal\Core\Database\Connection $connection
+ * @param Connection $connection
* Database connection.
- * @param \Drupal\Core\Queue\QueueInterface $text_track_queue
+ * @param QueueInterface $text_track_queue
* Text track queue object.
- * @param \Drupal\Core\Queue\QueueInterface $text_track_delete_queue
+ * @param 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) {
+ 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;
@@ -79,7 +83,8 @@ class BrightcoveVideoQueueWorker extends QueueWorkerBase implements ContainerFac
/**
* {@inheritdoc}
*/
- public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
+ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition)
+ {
return new static(
$configuration,
$plugin_id,
@@ -94,46 +99,49 @@ class BrightcoveVideoQueueWorker extends QueueWorkerBase implements ContainerFac
/**
* {@inheritdoc}
*/
- public function processItem($data) {
- /** @var \Brightcove\Item\Video\Video $video */
+ public function processItem($data)
+ {
+ /** @var Video $video */
$video = $data['video'];
- /** @var \Drupal\brightcove\Entity\BrightcoveVideo $video_entity */
- $video_entity = BrightcoveVideo::createOrUpdate($video, $this->storage, $data['api_client_id']);
+ if(in_array($video->getFolderId(), brightcove_extras_folders_allowed())) {
+ /** @var 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 (!empty($video_entity)) {
+ // Get existing text tracks.
+ $existing_text_tracks = [];
+ foreach ($video_entity->getTextTracks() as $text_track) {
+ /** @var 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;
+ 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()]);
+ // 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(),
+ ]);
}
- // 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);
+ // 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);
+ }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment