You are here

function upload_delete_revision in Drupal 5

Same name and namespace in other branches
  1. 4 modules/upload.module \upload_delete_revision()
  2. 6 modules/upload/upload.module \upload_delete_revision()
1 call to upload_delete_revision()
upload_nodeapi in modules/upload/upload.module
Implementation of hook_nodeapi().

File

modules/upload/upload.module, line 750
File-handling and attaching files to nodes.

Code

function upload_delete_revision($node) {
  if (is_array($node->files)) {
    foreach ($node->files as $file) {

      // Check if the file will be used after this revision is deleted
      $count = db_result(db_query('SELECT COUNT(fid) FROM {file_revisions} WHERE fid = %d', $file->fid));

      // if the file won't be used, delete it
      if ($count < 2) {
        db_query('DELETE FROM {files} WHERE fid = %d', $file->fid);
        file_delete($file->filepath);
      }
    }
  }

  // delete the revision
  db_query('DELETE FROM {file_revisions} WHERE vid = %d', $node->vid);
}