function _uc_file_gather_files in Ubercart 7.3
Same name and namespace in other branches
- 8.4 uc_file/uc_file.module \_uc_file_gather_files()
- 6.2 uc_file/uc_file.module \_uc_file_gather_files()
Retrieves an updated list of available downloads.
1 call to _uc_file_gather_files()
- uc_file_refresh in uc_file/
uc_file.module - Removes non-existent files and update the downloadable list.
File
- uc_file/
uc_file.module, line 1152 - Allows products to be associated with downloadable files.
Code
function _uc_file_gather_files() {
// Don't bother if the directory isn't set.
if (!($dir = variable_get('uc_file_base_dir', NULL))) {
return;
}
// Grab files and prepare the base dir for appending.
$files = file_scan_directory($dir, variable_get('uc_file_file_mask', '/.*/'));
$dir = substr($dir, -1) != '/' || substr($dir, -1) != '\\' ? $dir . '/' : $dir;
foreach ($files as $file) {
// Cut the base directory out of the path.
$filename = str_replace($dir, '', $file->uri);
$file_dir = dirname($filename);
$fid = NULL;
// Insert new entries.
if ($file_dir != '.' && !db_query("SELECT fid FROM {uc_files} WHERE filename = :name", array(
':name' => $file_dir . '/',
))
->fetchField()) {
$fid = db_insert('uc_files')
->fields(array(
'filename' => $file_dir . '/',
))
->execute();
}
if (!db_query("SELECT fid FROM {uc_files} WHERE filename = :name", array(
':name' => $filename,
))
->fetchField()) {
$fid = db_insert('uc_files')
->fields(array(
'filename' => $filename,
))
->execute();
}
// Invoke hook_uc_file_action().
if (!is_null($fid)) {
$file_object = uc_file_get_by_id($fid);
module_invoke_all('uc_file_action', 'insert', array(
'file_object' => $file_object,
));
unset($fid);
}
}
}