function file_entity_generate_file_batch_generate in File Entity (fieldable files) 7.3
Same name and namespace in other branches
- 7.2 file_entity.devel_generate.inc \file_entity_generate_file_batch_generate()
Implements hook_generate_file_batch_generate() using Devel generate api.
1 string reference to 'file_entity_generate_file_batch_generate'
- file_entity_generate_file_batch_info in ./
file_entity.devel_generate.inc - Implements hook_batch_info().
File
- ./
file_entity.devel_generate.inc, line 100 - Devel generate integration for the File Entity module.
Code
function file_entity_generate_file_batch_generate(array $file_types, $num, array &$context) {
if (empty($context['sandbox'])) {
module_load_include('inc', 'devel_generate');
$context['sandbox'] = array();
$context['sandbox']['progress'] = 0;
$context['sandbox']['max'] = $num;
$context['sandbox']['users'] = devel_get_users();
}
$limit = 20;
for ($i = 0; $i < min($limit, $context['sandbox']['max'] - $context['sandbox']['progress']); $i++) {
$type = array_rand(drupal_map_assoc($file_types), 1);
if ($uri = file_entity_generate_file($type)) {
$file = file_uri_to_object($uri, FALSE);
$file->uid = array_rand(drupal_map_assoc($context['sandbox']['users']), 1);
file_save($file);
if (!empty($file->fid)) {
$context['results'][] = $file->fid;
}
}
}
// Update our progress information.
$context['sandbox']['progress'] += $limit;
//$context['message'] = t('Deleted URL redirect @rid.', array('@rid' => end($rids)));
// 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'];
}
}