function ServiceAuditFilesMergeFileReferences::_auditfiles_merge_file_references_get_file_data in Audit Files 8
Retrieves information about an individual file from the database.
Parameters
int $file_name: The ID of the file to prepare for display.
Return value
array The row for the table on the report, with the file's information formatted for display.
File
- src/
ServiceAuditFilesMergeFileReferences.php, line 63 - providing the service that used in 'managed not used' functionality.
Class
Namespace
Drupal\auditfilesCode
function _auditfiles_merge_file_references_get_file_data($file_name, $date_format) {
$config = \Drupal::config('auditfiles_config.settings');
$connection = Database::getConnection();
$fid_query = 'SELECT fid FROM {file_managed} WHERE filename = :filename';
$fid_results = $connection
->query($fid_query, [
':filename' => $file_name,
])
->fetchAll();
if (count($fid_results) > 0) {
$fid_header = [
t('File ID'),
t('URI'),
t('Size (in bytes)'),
t('Date'),
];
$fid_rows = [];
$references = '<ul>';
foreach ($fid_results as $fid_result) {
$query = $connection
->select('file_managed', 'fm');
$query
->condition('fm.fid', $fid_result->fid);
$query
->fields('fm', [
'fid',
'uid',
'filename',
'uri',
'filemime',
'filesize',
'created',
'status',
]);
$results = $query
->execute()
->fetchAll();
$file = $results[0];
$references .= '<li>' . t('<strong>Fid: </strong> %id , <strong>Name : </strong> %file , <strong>File URI: </strong> %uri , <strong>Date: </strong> %date', [
'%id' => $file->fid,
'%file' => $file->filename,
'%uri' => $file->uri,
'%date' => format_date($file->created, $date_format),
]) . '</li>';
}
$references .= '</ul>';
$usage = new FormattableMarkup($references, []);
return [
'filename' => $file_name,
'references' => $usage,
];
}
}