You are here

function _uc_file_gather_files in Ubercart 6.2

Same name and namespace in other branches
  1. 8.4 uc_file/uc_file.module \_uc_file_gather_files()
  2. 7.3 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 1293

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 from the path
    $filename = str_replace($dir, '', $file->filename);
    $file_dir = dirname($filename);
    $fid = NULL;

    // Insert new entries.
    if (!db_result(db_query("SELECT fid FROM {uc_files} WHERE filename = '%s'", $file_dir . '/')) && $file_dir != '.') {
      db_query("INSERT INTO {uc_files} (filename) VALUES ('%s')", $file_dir . '/');
      $fid = db_last_insert_id('uc_files', 'fid');
    }
    if (!db_result(db_query("SELECT fid FROM {uc_files} WHERE filename = '%s'", $filename))) {
      db_query("INSERT INTO {uc_files} (filename) VALUES ('%s')", $filename);
      $fid = db_last_insert_id('uc_files', 'fid');
    }

    // Invoke hook_file_action.
    if (!is_null($fid)) {
      $file_object = uc_file_get_by_id($fid);
      module_invoke_all('file_action', 'insert', array(
        'file_object' => $file_object,
      ));
      unset($fid);
    }
  }
}