function _emvideo_update_get_duration in Embedded Media Field 6
Same name and namespace in other branches
- 6.3 contrib/emvideo/emvideo.install \_emvideo_update_get_duration()
- 6.2 contrib/emvideo/emvideo.install \_emvideo_update_get_duration()
Batch function to grab the duration for each video field.
1 string reference to '_emvideo_update_get_duration'
- emvideo_update_6016 in contrib/
emvideo/ emvideo.install - Add a duration column to existing fields.
File
- contrib/
emvideo/ emvideo.install, line 442 - Installation, configuration, and removal of the emvideo module.
Code
function _emvideo_update_get_duration($field, &$context) {
// Setup the first through
if (!isset($context['sandbox']['progress'])) {
$db_info = content_database_info($field);
$context['sandbox']['db_info'] = $db_info;
$context['sandbox']['table'] = $db_info['table'];
$context['sandbox']['col_embed'] = $db_info['columns']['embed']['column'];
$context['sandbox']['col_value'] = $db_info['columns']['value']['column'];
$context['sandbox']['col_provider'] = $db_info['columns']['provider']['column'];
$context['sandbox']['col_data'] = $db_info['columns']['data']['column'];
$context['sandbox']['col_duration'] = $db_info['columns']['duration']['column'];
$context['sandbox']['max'] = db_result(db_query("SELECT COUNT(*) FROM {" . $db_info['table'] . "} WHERE {$context['sandbox']['col_duration']} = 0"));
$context['sandbox']['progress'] = 0;
$context['sandbox']['current_node'] = 0;
}
// Work our way through the field values 50 rows at a time.
$limit = 50;
$result = db_query_range("SELECT * FROM {{$context['sandbox']['table']}} WHERE vid > %d AND {$context['sandbox']['col_duration']} = 0 ORDER BY vid ASC", $context['sandbox']['current_node'], 0, $limit);
while ($row = db_fetch_array($result)) {
// Fetch the duration from the provider.
$item = array(
'embed' => $row[$context['sandbox']['col_embed']],
'value' => $row[$context['sandbox']['col_value']],
'provider' => $row[$context['sandbox']['col_provider']],
'data' => unserialize($row[$context['sandbox']['col_data']]),
'duration' => $row[$context['sandbox']['col_duration']],
);
if ($item['provider'] && empty($item['duration'])) {
$duration = emfield_include_invoke('emvideo', $item['provider'], 'duration', $item);
if ($duration) {
db_query("UPDATE {{$context['sandbox']['table']}} SET {$context['sandbox']['col_duration']} = %d WHERE vid = %d", $duration, $row['vid']);
}
}
// Update our progress information.
$context['sandbox']['progress']++;
$context['sandbox']['current_node'] = $row['vid'];
}
// Inform the batch engine that we are not finished,
// and provide an estimation of the completion level we reached.
if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
}
}