You are here

function _auditfiles_managed_not_used_batch_display_process_files in Audit Files 7.3

The batch process operation for formatting the files for display on the page.

Parameters

string $date_format: The format to display time/date values in.

array $context: Used by the Batch API to keep track of and pass data from one operation to the next.

1 string reference to '_auditfiles_managed_not_used_batch_display_process_files'
_auditfiles_managed_not_used_batch_display_get_operations in ./auditfiles.managednotused.inc
Configures the operations for the batch process.

File

./auditfiles.managednotused.inc, line 323
Generates a report showing files in file_managed, but not in file_usage.

Code

function _auditfiles_managed_not_used_batch_display_process_files($date_format, array &$context) {
  if (empty($context['sandbox'])) {
    $context['sandbox'] = array();
    if (empty($context['results']['file_list'])) {
      $context['sandbox']['progress'] = 1;
      $context['sandbox']['max'] = 1;
    }
    else {
      $context['sandbox']['progress'] = 0;
      $context['sandbox']['max'] = count($context['results']['file_list']);
    }
  }
  if (empty($context['results']['files_to_display'])) {
    $context['results']['files_to_display'] = array();
  }
  if (!empty($context['results']['file_list'])) {
    $file_list = array_slice($context['results']['file_list'], 0, 20, TRUE);
    $query = 'SELECT fid, uid, filename, uri, filemime, filesize, timestamp, status
      FROM {file_managed}
      WHERE fid IN (:file_list)';
    $files_list = db_query($query, array(
      ':file_list' => $file_list,
    ))
      ->fetchAll();
    foreach ($files_list as $file) {
      $context['results']['files_to_display'][$file->fid] = array(
        'fid' => $file->fid,
        'uid' => $file->uid,
        'filename' => $file->filename,
        'uri' => $file->uri,
        'path' => drupal_realpath($file->uri),
        'filemime' => $file->filemime,
        'filesize' => number_format($file->filesize),
        'datetime' => format_date($file->timestamp, $date_format),
        'status' => ($file->status = 1) ? 'Permanent' : 'Temporary',
      );
      unset($context['results']['file_list'][$file->fid]);

      // Update the progress information.
      $context['sandbox']['progress']++;
      $context['message'] = t('Processing the file list. Processed file @num1 of @num2. Last file processed: !file_name.', array(
        '@num1' => $context['sandbox']['progress'],
        '@num2' => $context['sandbox']['max'],
        '!file_name' => $file->filename,
      ));
    }
  }
  if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
    $context['finished'] = $context['sandbox']['progress'] >= $context['sandbox']['max'];
  }
}