You are here

public function BrightcovePlaylistEntityController::delete in Brightcove Video Connect 7.7

Same name and namespace in other branches
  1. 7.6 brightcove.playlist.inc \BrightcovePlaylistEntityController::delete()

Overwrites DrupalDefaultEntityController::delete().

Overrides EntityAPIController::delete

File

./brightcove.playlist.inc, line 102
Brightcove playlist related functions.

Class

BrightcovePlaylistEntityController
Entity controller class for Brightcove client.

Code

public function delete($ids, DatabaseTransaction $transaction = NULL) {
  $entities = $ids ? $this
    ->load($ids) : FALSE;
  if (!$entities) {

    // Do nothing in case invalid or no ids have been passed.
    return;
  }
  foreach ($entities as $playlist_entity) {

    /** @var \Brightcove\Object\Playlist $playlist */
    $playlist = $playlist_entity->playlist;
    brightcove_try(function () use ($playlist, $playlist_entity) {

      /** @var \Brightcove\API\CMS $cms */
      list($cms, ) = brightcove_create_classes($playlist_entity->client);
      $cms
        ->deletePlaylist($playlist
        ->getId());

      // deletePlaylist() fails silently in case the client has no permission to
      // delete the playlist so we check here if it has been really removed or
      // not.
      try {
        $cms
          ->getPlaylist($playlist
          ->getId());
        watchdog('brightcove', 'Deleting the playlist @playlist has failed. Maybe the brightcove client has not enough permissions.', [
          '@playlist' => $playlist
            ->getId(),
        ], WATCHDOG_ERROR);
        drupal_set_message(t('Deleting the playlist @playlist has failed. Maybe the brightcove client has not enough permissions.', [
          '@playlist' => $playlist
            ->getId(),
        ]), 'error');
      } catch (Exception $e) {

        // Invalidate playlist cache.
        brightcove_invalidate_cache('brightcove:playlist', TRUE);
      }
    });
  }
}