You are here

function _auditfiles_filesnotindb in Audit Files 6.2

Same name and namespace in other branches
  1. 5 auditfiles.module \_auditfiles_filesnotindb()
  2. 6.3 notindb.admin.inc \_auditfiles_filesnotindb()

Helper function - retrieve sorted list of files that are on the server but not in the database

1 call to _auditfiles_filesnotindb()
auditfiles_notindb_form in ./notindb.admin.inc
Form definition for audit files not in database

File

./notindb.admin.inc, line 190
Callback and functions to generate files not in database report

Code

function _auditfiles_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 = _auditfiles_directorytoarray(realpath(file_create_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('./');

  // Get the exclusions string
  $exclusions = _auditfiles_get_exclusions();

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

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

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

      // Exclude files, paths and extensions according to the retrieved exclusions string
      if (!preg_match('@' . $exclusions . '@', $file) || !$exclusions) {

        // 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
          $file = preg_replace('@^' . preg_quote(file_directory_path()) . '/@', '', $file);
          $filesnotindb[] = $file;
        }
      }
    }
  }
  return $filesnotindb;
}