BrightcoveVideoDeleteQueueWorker.php in Brightcove Video Connect 3.x
File
src/Plugin/QueueWorker/BrightcoveVideoDeleteQueueWorker.php
View source
<?php
namespace Drupal\brightcove\Plugin\QueueWorker;
use Brightcove\API\Exception\APIException;
use Drupal\brightcove\BrightcoveUtil;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\QueueWorkerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class BrightcoveVideoDeleteQueueWorker extends QueueWorkerBase implements ContainerFactoryPluginInterface {
protected $storage;
public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityStorageInterface $storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->storage = $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_video'));
}
public function processItem($data) {
try {
$cms = BrightcoveUtil::getCmsApi($data->api_client);
$cms
->getVideo($data->video_id);
} catch (APIException $e) {
if ($e
->getCode() == 404) {
$video = $this->storage
->load($data->bcvid);
if (!empty($video)) {
$video
->delete(TRUE);
}
}
else {
throw new APIException($e
->getMessage(), $e
->getCode(), $e, $e
->getResponseBody());
}
}
}
}