You are here

function filehash_bulk_process in File Hash 7

Batch generate file hashes.

1 string reference to 'filehash_bulk_process'
filehash_bulk_submit in ./filehash.admin.inc
Submit callback for File Hash bulk generate.

File

./filehash.admin.inc, line 65
File Hash configuration.

Code

function filehash_bulk_process(&$context) {
  if (!isset($context['results']['processed'])) {
    $context['results']['processed'] = 0;
    $query = new EntityFieldQuery();
    $context['sandbox']['count'] = $query
      ->entityCondition('entity_type', 'file')
      ->addMetaData('account', user_load(1))
      ->count()
      ->execute();
  }
  $query = new EntityFieldQuery();
  $files = $query
    ->entityCondition('entity_type', 'file')
    ->addMetaData('account', user_load(1))
    ->range($context['results']['processed'], 1)
    ->execute();
  foreach ($files['file'] as $file) {
    $file = file_load($file->fid);
    $context['message'] = t('Processed file ID !fid (%filename).', array(
      '!fid' => $file->fid,
      '%filename' => $file->filename,
    ));
    $context['results']['processed']++;
    $context['finished'] = $context['results']['processed'] / $context['sandbox']['count'];
  }
}