function _auditfiles_not_in_database_batch_add_process_file in Audit Files 7.4
Same name and namespace in other branches
- 7.3 auditfiles.notindatabase.inc \_auditfiles_not_in_database_batch_add_process_file()
Adds the specified file to the database.
Parameters
string $filename: The full pathname to the file to add to the database.
1 call to _auditfiles_not_in_database_batch_add_process_file()
- _auditfiles_not_in_database_batch_add_process_batch in ./
auditfiles.notindatabase.inc - The batch process for adding the file.
File
- ./
auditfiles.notindatabase.inc, line 518 - Generates a report showing files on the server, but not in the database.
Code
function _auditfiles_not_in_database_batch_add_process_file($filename) {
global $user;
$file = new stdClass();
$file->uid = $user->uid;
// Get the path to the file relative to it's file storage location.
$filename = preg_replace('@' . preg_quote(drupal_realpath('./')) . '.@', '', $filename);
// Get the scheme's path.
$scheme_path = variable_get('file_' . file_default_scheme() . '_path', conf_path() . '/files');
$filename = preg_replace('@' . preg_quote($scheme_path) . '.@', '', $filename);
$file->filename = trim(basename($filename));
$file->uri = file_build_uri($filename);
$file->filemime = file_get_mimetype($file->uri);
$file->filesize = filesize(drupal_realpath($file->uri));
$file->status = FILE_STATUS_PERMANENT;
$file->timestamp = REQUEST_TIME;
$results = drupal_write_record('file_managed', $file);
if ($results === FALSE) {
drupal_set_message(t('Failed to add %file to the database.', array(
'%file' => $filename,
)));
// Remove the files from the list of files to display.
$rows = variable_get('auditfiles_not_in_database_files_to_display', array());
unset($rows[$filename]);
variable_set('auditfiles_not_in_database_files_to_display', $rows);
}
else {
drupal_set_message(t('Sucessfully added %file to the database.', array(
'%file' => $filename,
)));
}
}