function _auditfiles_referenced_not_used_batch_add_process_file in Audit Files 7.3
Same name and namespace in other branches
- 7.4 auditfiles.referencednotused.inc \_auditfiles_referenced_not_used_batch_add_process_file()
Adds the specified file to the file_usage table.
Parameters
string $reference_id: The ID for keeping track of the reference.
1 call to _auditfiles_referenced_not_used_batch_add_process_file()
- _auditfiles_referenced_not_used_batch_add_process_batch in ./
auditfiles.referencednotused.inc - The batch process for adding the file.
File
- ./
auditfiles.referencednotused.inc, line 611 - Generates report showing files referenced by content, but not in file_usage.
Code
function _auditfiles_referenced_not_used_batch_add_process_file($reference_id) {
$reference_id_parts = explode('.', $reference_id);
$data = array(
'fid' => $reference_id_parts[4],
// @todo This is hard coded for now, but need to determine how to figure out
// which module needs to be here.
'module' => 'file',
'type' => $reference_id_parts[3],
'id' => $reference_id_parts[2],
'count' => 1,
);
// Make sure the file is not already in the database.
$query = 'SELECT fid FROM {file_usage}
WHERE fid = :fid AND module = :module AND type = :type AND id = :id';
$existing_file = db_query($query, array(
':fid' => $data['fid'],
':module' => $data['module'],
':type' => $data['type'],
':id' => $data['id'],
))
->fetchAll();
if (empty($existing_file)) {
// The file is not already in the database, so add it.
db_insert('file_usage')
->fields($data)
->execute();
// Remove the files from the list of files to display.
$rows = variable_get('auditfiles_referenced_not_used_files_to_display', array());
unset($rows[$reference_id]);
variable_set('auditfiles_referenced_not_used_files_to_display', $rows);
}
else {
drupal_set_message(t('The file is already in the file_usage table (file id: "@fid", module: "@module", type: "@type", entity id: "@id").', array(
'@fid' => $data['fid'],
'@module' => $data['module'],
'@type' => $data['type'],
'@id' => $data['id'],
)), 'error');
}
}