public function video_amazon_s3::queue in Video 6.4
File
- plugins/
video_s3/ video_s3.lib.inc, line 154
Class
Code
public function queue() {
$sql = db_query("SELECT vid, fid FROM {video_s3} WHERE status = %d LIMIT %d", VIDEO_S3_PENDING, $this->limit);
while ($row = db_fetch_object($sql)) {
module_load_include('inc', 'video', '/includes/conversion');
// We need to check if this file id exists in our transcoding table.
// Skip unfinished ffmpeg jobs
$result = db_query('SELECT f.*, vf.data FROM {files} f LEFT JOIN {video_files} vf USING(fid) WHERE f.fid = %d AND (vf.status IS NULL OR vf.status = %d)', $row->fid, VIDEO_RENDERING_COMPLETE);
if (!($video = db_fetch_object($result))) {
$this
->watchdog('Could not find the file id %fid or it is still queued for ffmpeg processing.', array(
'%fid' => $row->fid,
), WATCHDOG_DEBUG, $row);
continue;
}
// Update our status to working.
$this
->working($row->vid);
$success = true;
// Add all ffmpeg converted variants
if (!empty($video->data)) {
foreach (unserialize($video->data) as $file) {
if (!$this
->pushFile($file)) {
$success = false;
}
}
}
if ($success) {
// Upload the original
if ($video = $this
->pushFile($video)) {
$video->vid = $row->vid;
$this
->update($video);
}
else {
$success = false;
}
}
if (!$success) {
$this
->failed($row->vid);
}
}
// Update Expires headers on currently-uploaded files.
// First, make sure this is a good time to do this. It doesn't make much
// sense to do this more often than the Expires offset.
$expires_offset = variable_get('amazon_s3_expires_offset', 604800);
if ($expires_offset !== 'none' && $expires_offset != 0 && variable_get('amazon_s3_expires_last_cron', 0) + $expires_offset < time()) {
$active = db_query('SELECT bucket, filename, filepath, filemime FROM {video_s3} WHERE status = %d', VIDEO_S3_COMPLETE);
$permission = variable_get('amazon_s3_private', FALSE) ? AmazonS3::ACL_PRIVATE : AmazonS3::ACL_PUBLIC;
$headers = array(
'Expires' => gmdate('r', time() + $expires_offset),
);
// Note that Cache-Control headers are always relative values (X seconds
// in the future from the point they are sent), so we don't need to update
// them regularly like we do with Expires headers. However, if we don't
// send one, the one that is set (if any) will be deleted. (Also, if the
// human has changed this setting on the administration page, we want to
// update video info accordingly.)
// @todo: Logic problems: This only updates when expires headers update…
// Might want to find a way so that these update immediately when the
// admin settings form is submitted.
$cc = variable_get('amazon_s3_cache_control_max_age', 'none');
if ($cc !== 'none') {
$headers['Cache-Control'] = 'max-age=' . $cc;
}
while ($file = db_fetch_object($active)) {
$this
->update_headers($file, $permission, $headers);
}
variable_set('amazon_s3_expires_last_cron', time());
}
}