You are here

public function video_s3::delete_video in Video 6.5

Delete the video from the file system.

Overrides video_filesystem::delete_video

File

plugins/video_s3/filesystem/video_s3.inc, line 307
Class file used to store videos in Amazon S3.

Class

video_s3

Code

public function delete_video(stdClass $video) {

  // Find the bucket
  if (!($s3info = $this->s3
    ->verify($video->fid))) {
    return;
  }

  // Remove the original file
  $this->s3->s3
    ->delete_object($s3info->bucket, $video->filepath);

  // Remove converted files
  if (!empty($video->data)) {
    foreach ($video->data as $subvideo) {
      $filepath = NULL;
      if (isset($subvideo->url)) {

        // This video is converted by Zencoder
        $parts = parse_url($subvideo->url);
        $filepath = ltrim($parts['path'], '/');
      }
      else {

        // This video is locally converted
        $filepath = $subvideo->filepath;
      }

      // Delete the remote copy
      $this->s3->s3
        ->delete_object($s3info->bucket, $filepath);

      // Delete the local copy
      file_delete($filepath);
    }
  }

  // Remove thumbnails on S3
  $thumb_folder = video_thumb_path($video, FALSE) . '/';
  $thumbfilenames = $this->s3->s3
    ->get_object_list($s3info->bucket, array(
    'prefix' => $thumb_folder,
  ));
  if (!empty($thumbfilenames)) {
    $objects = array();
    foreach ($thumbfilenames as $thumb) {
      $objects[] = array(
        'key' => $thumb,
      );
    }
    $this->s3->s3
      ->delete_objects($s3info->bucket, array(
      'objects' => $objects,
    ));
  }

  // Remove thumbnails locally
  if (is_dir($thumb_folder)) {
    rmdirr($thumb_folder);

    // Delete any entries in the files table that may refer to the above path.
    db_query('DELETE FROM {files} WHERE filepath LIKE "%b%%"', strtr(db_escape_string($thumb_folder), array(
      '%' => '\\%',
      '_' => '\\_',
    )));
  }
  db_query('DELETE FROM {video_s3} WHERE fid = %d', $video->fid);
}