You are here

function _auditfiles_referenced_not_used_get_file_data in Audit Files 7.3

Same name and namespace in other branches
  1. 7.4 auditfiles.referencednotused.inc \_auditfiles_referenced_not_used_get_file_data()

Retrieves information about an individual file from the database.

Parameters

array $row_data: The data to use for creating the row.

Return value

array The row for the table on the report, with the file's information formatted for display.

1 call to _auditfiles_referenced_not_used_get_file_data()
auditfiles_referenced_not_used_form in ./auditfiles.referencednotused.inc
Generates the report.

File

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

Code

function _auditfiles_referenced_not_used_get_file_data(array $row_data) {

  // Get the data for this record.
  $query = 'SELECT * FROM {' . $row_data['table'] . '} WHERE ' . $row_data['column'] . ' = ' . $row_data['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->{$row_data['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' => $row_data['table'] . '.' . $row_data['column'],
    'table' => array(
      'data' => $row_data['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->{$row_data['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;
  }
  return $row;
}