You are here

function _auditfiles_not_on_server_batch_display_get_files in Audit Files 7.3

The batch process for displaying the files.

Parameters

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_not_on_server_batch_display_get_files'
_auditfiles_not_on_server_batch_display_get_operations in ./auditfiles.notonserver.inc
Configures the operations for the batch process.

File

./auditfiles.notonserver.inc, line 267
Generates a report showing files in the database, but not on the server.

Code

function _auditfiles_not_on_server_batch_display_get_files(array &$context) {
  if (empty($context['sandbox'])) {
    $context['sandbox'] = array();
    $context['sandbox']['progress'] = 0;
    $context['sandbox']['current_file'] = 0;
    $query = 'SELECT COUNT(DISTINCT fm.fid) FROM {file_managed} fm';
    $record_count = db_query($query)
      ->fetchField();
    $batch_size = variable_get('auditfiles_report_options_batch_size', 1000);
    if ($batch_size > 0 && $record_count > $batch_size) {
      $context['sandbox']['max'] = $batch_size;
    }
    else {
      $context['sandbox']['max'] = $record_count;
    }
  }
  if (empty($context['results']['file_list'])) {
    $context['results']['file_list'] = array();
  }

  // Get the file data from the database.
  // This cannot be sorted any other way here, or the results are not complete.
  $query = 'SELECT fid, filename, uri
    FROM {file_managed}
    WHERE fid > :fid
    ORDER BY fid ASC
    LIMIT 20';
  $files = db_query($query, array(
    ':fid' => $context['sandbox']['current_file'],
  ))
    ->fetchAll();
  foreach ($files as $file) {

    // Get the path for the file.
    if (empty($file->uri)) {

      // There is no URI listed for the file . Add the file to the array.
      $context['results']['file_list'][$file->fid] = $file->fid;
    }
    else {
      $target = drupal_realpath($file->uri);
      if (!file_exists($target)) {

        // The file does not exist. Add the file to the array.
        $context['results']['file_list'][$file->fid] = $file->fid;
      }
    }

    // Update the progress information.
    $context['sandbox']['progress']++;
    $context['sandbox']['current_file'] = $file->fid;
    $context['message'] = t('Getting the list of files. 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'];
  }
}