public function video_amazon_s3::delete in Video 6.4
File
- plugins/
video_s3/ video_s3.lib.inc, line 102
Class
Code
public function delete($fid) {
// Lets get our file no matter the status and delete it.
if ($video = $this
->verify($fid)) {
if ($video->bucket) {
// It has been pushed to amazon so lets remove it.
$filepath = $video->filepath;
// For old video's (pre-4.5), the filename property is actually the path we need
if (strpos('/', $video->filename) !== FALSE) {
$filepath = $video->filename;
}
$this->s3
->delete_object($video->bucket, $filepath);
// Remove ffmpeg converted files
$row = db_fetch_object(db_query('SELECT data FROM {video_files} WHERE data IS NOT NULL AND fid = %d', $fid));
if ($row) {
foreach (unserialize($row->data) as $subvideo) {
$this->s3
->delete_object($video->bucket, $subvideo->filepath);
}
}
// TODO: move this to video_zencoder
if (module_exists('video_zencoder')) {
// Delete converted files added by Zencoder
$row = db_fetch_object(db_query('SELECT data FROM {video_zencoder} WHERE data IS NOT NULL AND fid = %d', $fid));
if ($row) {
foreach (unserialize($row->data) as $subvideo) {
$parts = parse_url($subvideo->url);
$this->s3
->delete_object($video->bucket, ltrim($parts['path'], '/'));
}
}
// Delete thumbnails added by Zencoder
$thumb_folder = video_thumb_path($video, FALSE) . '/';
$thumbfilenames = $this->s3
->get_object_list($video->bucket, array(
'prefix' => $thumb_folder,
));
if (!empty($thumbfilenames)) {
$objects = array();
foreach ($thumbfilenames as $thumb) {
$objects[] = array(
'key' => $thumb,
);
}
$this->s3
->delete_objects($video->bucket, array(
'objects' => $objects,
));
}
}
}
// Lets delete our record from the database.
db_query('DELETE FROM {video_s3} WHERE vid = %d', $video->vid);
}
}