You are here

function _auditfiles_referenced_not_used_batch_display_process_files in Audit Files 7.3

Retrieves information about an individual file from the database.

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_referenced_not_used_batch_display_process_files'
_auditfiles_referenced_not_used_batch_display_get_operations in ./auditfiles.referencednotused.inc
Configures the operations for the batch process.

File

./auditfiles.referencednotused.inc, line 394
Generates report showing files referenced by content, but not in file_usage.

Code

function _auditfiles_referenced_not_used_batch_display_process_files(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);
    foreach ($file_list as $reference_id => $file) {

      // Get the data for this record.
      $query = 'SELECT * FROM {' . $file['table'] . '} WHERE ' . $file['column'] . ' = ' . $file['file_id'];
      $result = db_query($query)
        ->fetchAll();
      $result = reset($result);
      if ($result->entity_type == 'node') {
        $entity_id_display = l('node/' . $result->entity_id, 'node/' . $result->entity_id);
      }
      else {
        $entity_id_display = $result->entity_id;
      }

      // Add the initial data to the row.
      $row = array(
        'file_id' => $result->{$file['column']},
        'entity_type' => $result->entity_type,
        'bundle' => array(
          'data' => $result->bundle,
          'hidden' => TRUE,
        ),
        'entity_id' => array(
          'data' => $result->entity_id,
          'hidden' => TRUE,
        ),
        'entity_id_display' => $entity_id_display,
        'field' => $file['table'] . '.' . $file['column'],
        'table' => array(
          'data' => $file['table'],
          'hidden' => TRUE,
        ),
        'uri' => 'No file object exists for this reference.',
        'filename' => array(
          'data' => '',
          'hidden' => TRUE,
        ),
        'filemime' => '--',
        'filesize' => '--',
      );

      // If there is a file in the file_managed table, add some of that
      // information to the row, too.
      $file_managed = file_load($result->{$file['column']});
      if (!empty($file_managed)) {
        $row['uri'] = $file_managed->uri;
        $row['filename'] = array(
          'data' => $file_managed->filename,
          'hidden' => TRUE,
        );
        $row['filemime'] = $file_managed->filemime;
        $row['filesize'] = $file_managed->filesize;
      }
      $context['results']['files_to_display'][$reference_id] = $row;

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