1 file.module file_type_classify_batch($fids, &$context)

Batch operation callback to classify the types of managed files.

Unlike Drupal 7, the file_managed table in Backdrop contains a type column. This process classifies the file types when upgrading from a D7 site.

See also

file_needs_type_classification()

File

core/modules/file/file.module, line 3386
Defines a "managed_file" Form API field and a "file" field for Field module.

Code

function file_type_classify_batch($fids, &$context) {
  if (!isset($context['sandbox']['current_item'])) {
    $context['sandbox']['current_item'] = 0;
    $context['sandbox']['count'] = count($fids);
  }

  // Process 15 files at a time.
  $limit = min($context['sandbox']['current_item'] + 15, $context['sandbox']['count']);
  while ($context['sandbox']['current_item'] < $limit) {
    $fid = $fids[$context['sandbox']['current_item']];
    file_type_determine($fid);
    $context['results'][] = $fid;
    $context['message'] = t('Now processing file ID %fid', array('%fid' => $fid));
    $context['sandbox']['current_item']++;
  }
  $context['finished'] = $context['sandbox']['current_item'] / $context['sandbox']['count'];
}