You are here

class BrightcoveSubscriptionDeleteQueueWorker in Brightcove Video Connect 3.x

Same name and namespace in other branches
  1. 8.2 src/Plugin/QueueWorker/BrightcoveSubscriptionDeleteQueueWorker.php \Drupal\brightcove\Plugin\QueueWorker\BrightcoveSubscriptionDeleteQueueWorker
  2. 8 src/Plugin/QueueWorker/BrightcoveSubscriptionDeleteQueueWorker.php \Drupal\brightcove\Plugin\QueueWorker\BrightcoveSubscriptionDeleteQueueWorker

Processes Entity Sync Tasks for Subscription.

Plugin annotation


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

Hierarchy

Expanded class hierarchy of BrightcoveSubscriptionDeleteQueueWorker

File

src/Plugin/QueueWorker/BrightcoveSubscriptionDeleteQueueWorker.php, line 20

Namespace

Drupal\brightcove\Plugin\QueueWorker
View source
class BrightcoveSubscriptionDeleteQueueWorker extends QueueWorkerBase {

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

    /** @var array $data */
    if (!empty($data['local_only'])) {
      $brightcove_subscription = BrightcoveSubscription::loadByBcSid($data['subscription_id']);
      if (!empty($brightcove_subscription)) {
        $brightcove_subscription
          ->delete(TRUE);
      }
    }
    else {

      // Check the Subscription if it is available on Brightcove or not.
      try {
        $cms = BrightcoveUtil::getCmsApi($data['api_client_id']);
        $cms
          ->getSubscription($data['subscription_id']);
      } catch (APIException $e) {

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

          /** @var \Drupal\brightcove\Entity\BrightcoveSubscription $subscription */
          $brightcove_subscription = BrightcoveSubscription::loadByBcSid($data['subscription_id']);
          if (!empty($brightcove_subscription)) {

            // In case of a default subscription, unset the entity's
            // association with the Brightcove entity, but keep a local entity
            // in Drupal without the Brightcove ID and set its status to
            // disabled.
            if ($brightcove_subscription
              ->isDefault()) {
              $brightcove_subscription
                ->setBcSid(NULL);
              $brightcove_subscription
                ->setStatus(FALSE);
              $brightcove_subscription
                ->save();
            }
            else {
              $brightcove_subscription
                ->delete(TRUE);
            }
          }
        }
        elseif ($e
          ->getCode() == 401) {
          watchdog_exception('brightcove', $e, 'Access denied for Notification.', [], RfcLogLevel::WARNING);
        }
        else {
          throw $e;
        }
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BrightcoveSubscriptionDeleteQueueWorker::processItem public function Works on a single queue item. Overrides QueueWorkerInterface::processItem
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 2
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.
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. 98