You are here

public function BrightcoveVideo::delete in Brightcove Video Connect 3.x

Same name and namespace in other branches
  1. 8.2 src/Entity/BrightcoveVideo.php \Drupal\brightcove\Entity\BrightcoveVideo::delete()
  2. 8 src/Entity/BrightcoveVideo.php \Drupal\brightcove\Entity\BrightcoveVideo::delete()

Parameters

bool $local_only: Whether to delete the local version only or both local and Brightcove versions.

Overrides EntityBase::delete

File

src/Entity/BrightcoveVideo.php, line 911

Class

BrightcoveVideo
Defines the Brightcove Video entity.

Namespace

Drupal\brightcove\Entity

Code

public function delete($local_only = FALSE) {

  // Delete video from Brightcove.
  if (!$this
    ->isNew() && !$local_only) {
    $api_client = BrightcoveUtil::getApiClient($this
      ->getApiClient());
    $client = $api_client
      ->getClient();

    // Delete video references.
    try {
      $client
        ->request('DELETE', 1, 'cms', $api_client
        ->getAccountId(), "/videos/{$this->getBrightcoveId()}/references", NULL);

      // Delete video.
      $cms = BrightcoveUtil::getCmsApi($this
        ->getApiClient());
      $cms
        ->deleteVideo($this
        ->getBrightcoveId());
      parent::delete();
    } catch (APIException $e) {
      if ($e
        ->getCode() == 404) {
        drupal_set_message(t('The video was not found on Brightcove, only the local version was deleted.'), 'warning');
        parent::delete();
      }
      else {
        drupal_set_message(t('There was an error while trying to delete the Video from Brightcove: @error', [
          '@error' => $e
            ->getMessage(),
        ]), 'error');
      }
    }
  }
  else {
    parent::delete();
  }
}