You are here

public function BrightcoveSubscription::deleteFromBrightcove in Brightcove Video Connect 8

Same name and namespace in other branches
  1. 8.2 src/Entity/BrightcoveSubscription.php \Drupal\brightcove\Entity\BrightcoveSubscription::deleteFromBrightcove()
  2. 3.x src/Entity/BrightcoveSubscription.php \Drupal\brightcove\Entity\BrightcoveSubscription::deleteFromBrightcove()

Delete the Subscription from Brightcove only.

Throws

\Drupal\brightcove\Entity\Exception\BrightcoveSubscriptionException

\Exception

1 call to BrightcoveSubscription::deleteFromBrightcove()
BrightcoveSubscription::delete in src/Entity/BrightcoveSubscription.php

File

src/Entity/BrightcoveSubscription.php, line 544

Class

BrightcoveSubscription
Defines the Brightcove Subscription entity.

Namespace

Drupal\brightcove\Entity

Code

public function deleteFromBrightcove() {
  try {
    $cms = BrightcoveUtil::getCmsApi($this->apiClient
      ->id());
    $cms
      ->deleteSubscription($this
      ->getBcSid());
  } catch (\Exception $e) {

    // In case of the subscription cannot be found on Brightcove, just ignore,
    // otherwise throw an exception.
    if ($e
      ->getCode() != 404) {
      $message = 'Failed to delete Subscription with @endpoint endpoint (ID: @bcsid).';
      $replacement = [
        '@endpoint' => $this
          ->getEndpoint(),
        '@bcsid' => $this
          ->getBcSid(),
      ];
      watchdog_exception('brightcove', $e, $message, $replacement);
      throw new BrightcoveSubscriptionException(strtr($message, $replacement), $e
        ->getCode(), $e);
    }
  }

  // In case of a default subscription set status to disabled and unset the
  // Brightcove ID.
  if ($this
    ->isDefault()) {
    $this
      ->setBcSid(NULL);
    $this
      ->setStatus(FALSE);
    $this
      ->save();
  }
}