You are here

function file_entity_generate_file_batch_delete in File Entity (fieldable files) 7.3

Same name and namespace in other branches
  1. 7.2 file_entity.devel_generate.inc \file_entity_generate_file_batch_delete()

Implements hook_batch_delete().

1 string reference to 'file_entity_generate_file_batch_delete'
file_entity_generate_file_batch_info in ./file_entity.devel_generate.inc
Implements hook_batch_info().

File

./file_entity.devel_generate.inc, line 73
Devel generate integration for the File Entity module.

Code

function file_entity_generate_file_batch_delete(array $file_types, array &$context) {
  if (empty($context['sandbox'])) {
    $context['sandbox'] = array();
    $context['sandbox']['progress'] = 0;
    $context['sandbox']['current_fid'] = 0;
    $context['sandbox']['max'] = db_query('SELECT COUNT(DISTINCT fid) FROM {file_managed} WHERE type IN (:types)', array(
      ':types' => $file_types,
    ))
      ->fetchField();
  }
  $limit = 20;
  $fids = db_query_range("SELECT fid FROM {file_managed} WHERE type IN (:types) AND fid > :fid ORDER BY fid", 0, $limit, array(
    ':types' => $file_types,
    ':fid' => $context['sandbox']['current_fid'],
  ))
    ->fetchCol();
  file_delete_multiple($fids);

  // Update our progress information.
  $context['sandbox']['progress'] += count($fids);
  $context['sandbox']['current_rid'] = end($fids);
  $context['message'] = t('Deleted file @fid.', array(
    '@fid' => $context['sandbox']['current_rid'],
  ));

  // 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'];
  }
}