You are here

function _flashnode_filesnotindb in Flash Node 6.2

Same name and namespace in other branches
  1. 5.6 flashnode.module \_flashnode_filesnotindb()
  2. 5.3 flashnode.module \_flashnode_filesnotindb()
  3. 6.3 flashnode.import.inc \_flashnode_filesnotindb()

Return an array of files that are not currently in the {files} table

1 call to _flashnode_filesnotindb()
flashnode_import_form in ./flashnode.import.inc
Form definition function to show list of files available for import

File

./flashnode.import.inc, line 85

Code

function _flashnode_filesnotindb() {

  // Prepare array to hold results
  $filesnotindb = array();

  // Get all the files out the {files} table and store as qualified path
  $result = db_query('SELECT filepath FROM {files} ORDER BY filepath ASC');
  $filesindb = array();
  while ($file = db_fetch_object($result)) {
    $filesindb[] = file_create_path($file->filepath);
  }

  // Get all the files out of the directory structure
  $filesonserver = _flashnode_directorytoarray(realpath(file_create_path(variable_get('flashnode_default_path', FLASHNODE_DEFAULT_PATH))), TRUE);

  // Sort the rows to make it easier to compare to file listing in FTP
  asort($filesonserver);

  // Get the root path - will need this later
  $root = realpath('.');

  // Process each result in turn
  foreach ($filesonserver as $file) {

    // Strip out the root path to leave just a drupal path
    $file = preg_replace('@' . preg_quote($root) . '.@', '', $file);

    // Correct for Windows using \ in place of /
    $file = str_replace("\\", "/", $file);

    // Check it isn't a directory - not interested
    if (!file_check_directory($file)) {

      // Check to see if file is NOT in the database
      if (!in_array($file, $filesindb)) {

        // If we get here we have a file that isn't in the database
        $filesnotindb[] = $file;
      }
    }
  }
  return $filesnotindb;
}