function media_import_batch_import_files in D7 Media 7
BatchAPI callback op for media import.
1 string reference to 'media_import_batch_import_files'
- media_import_submit in includes/
media.admin.inc - Submit handler for media_import().
File
- includes/
media.admin.inc, line 513 - This file contains the admin functions for the Media module.
Code
function media_import_batch_import_files($files, &$context) {
if (!isset($context['sandbox']['files'])) {
// This runs the first time the batch runs.
// This is stupid, but otherwise, I don't think it will work...
$context['results'] = array(
'success' => array(),
'errors' => array(),
);
$context['sandbox']['max'] = count($files);
$context['sandbox']['files'] = $files;
}
$files =& $context['sandbox']['files'];
// Take a cut of files. Let's do 10 at a time.
$length = count($files) > media_variable_get('import_batch_size') ? media_variable_get('import_batch_size') : count($files);
$to_process = array_splice($files, 0, $length);
$image_in_message = '';
foreach ($to_process as $file) {
try {
$file_obj = media_parse_to_file($file);
$context['results']['success'][] = $file;
if (!$image_in_message) {
// @todo Is this load step really necessary? When there's time, test
// this, and either remove it, or comment why it's needed.
$loaded_file = file_load($file_obj->fid);
$image_in_message = file_view_file($loaded_file, 'media_preview');
}
} catch (Exception $e) {
$context['results']['errors'][] = $file . " Reason: " . $e
->getMessage();
}
}
$context['message'] = "Importing " . theme('item_list', array(
'items' => $to_process,
));
$context['message'] .= drupal_render($image_in_message);
// Just for kicks, show an image we are importing
$context['finished'] = ($context['sandbox']['max'] - count($files)) / $context['sandbox']['max'];
}