function _auditfiles_not_in_database_batch_display_get_files in Audit Files 7.3
Recurse directories and add files to an array.
Parameters
array $context: Used by the Batch API to keep track of data and pass it from one operation to the next.
1 string reference to '_auditfiles_not_in_database_batch_display_get_files'
- _auditfiles_not_in_database_batch_display_get_operations in ./
auditfiles.notindatabase.inc - Configures the operations for the batch process.
File
- ./
auditfiles.notindatabase.inc, line 267 - Generates a report showing files on the server, but not in the database.
Code
function _auditfiles_not_in_database_batch_display_get_files(array &$context) {
if (empty($context['sandbox'])) {
$context['sandbox'] = array();
$context['sandbox']['progress'] = 0;
// Get the starter list of files from the root directory.
$file_system_stream = variable_get('auditfiles_file_system_path', 'public');
$context['sandbox']['drupal_path'] = variable_get('file_' . $file_system_stream . '_path', conf_path() . '/files');
$context['sandbox']['real_path'] = drupal_realpath($file_system_stream . '://');
$files = _auditfiles_not_in_database_get_files($context['sandbox']['real_path']);
if (!empty($files)) {
$context['sandbox']['exclusions'] = _auditfiles_get_exclusions();
$context['sandbox']['files'] = _auditfiles_not_in_database_report_processing_merge_file_lists(array(), $files, $context['sandbox']['real_path'], '', $context['sandbox']['exclusions']);
}
$context['sandbox']['batch_size'] = variable_get('auditfiles_report_options_batch_size', 1000);
if ($context['sandbox']['batch_size'] > 0) {
$context['sandbox']['max'] = $context['sandbox']['batch_size'];
}
else {
$context['sandbox']['max'] = count($context['sandbox']['files']);
}
}
if (empty($context['results'])) {
$context['results'] = array();
}
if (empty($context['results']['file_list'])) {
$context['results']['file_list'] = array();
}
if (!empty($context['sandbox']['files'])) {
// Process 20 files at a time, so the batch process has an opportunity to
// reset itself.
$file_list = array_slice($context['sandbox']['files'], 0, 20, TRUE);
foreach ($file_list as $key => $context['sandbox']['file']) {
if (is_dir($context['sandbox']['real_path'] . DIRECTORY_SEPARATOR . $context['sandbox']['file'])) {
// Scan the directory and append the files to the files array.
$found_files = _auditfiles_not_in_database_get_files($context['sandbox']['real_path'] . DIRECTORY_SEPARATOR . $context['sandbox']['file']);
if (!empty($found_files)) {
// Add the newly found files to the end of the files array.
$context['sandbox']['files'] = _auditfiles_not_in_database_report_processing_merge_file_lists($context['sandbox']['files'], $found_files, $context['sandbox']['real_path'], $context['sandbox']['file'], $context['sandbox']['exclusions']);
// Update the max file count.
if (empty($context['sandbox']['batch_size'])) {
$context['sandbox']['max'] = count($context['sandbox']['files']);
}
}
}
else {
// Add the file to the list.
$context['results']['file_list'][] = _auditfiles_not_in_database_fix_path_separators($context['sandbox']['file']);
// Check to see if the array has reached its limit.
if (count($context['results']['file_list']) >= $context['sandbox']['max']) {
$context['sandbox']['progress'] = $context['sandbox']['max'];
}
else {
$context['sandbox']['progress']++;
}
}
unset($context['sandbox']['files'][$key]);
// Update the progress information.
$context['message'] = t('Getting the list of files. Processed file @num1 of @num2. Last file processed: !file_name.', array(
'@num1' => $context['sandbox']['progress'],
'@num2' => $context['sandbox']['max'],
'!file_name' => $context['sandbox']['file'],
));
}
}
else {
$context['sandbox']['progress'] = $context['sandbox']['max'];
}
if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
$context['finished'] = $context['sandbox']['progress'] >= $context['sandbox']['max'];
}
}