You are here

function upload_delete_revision in Drupal 4

Same name and namespace in other branches
  1. 5 modules/upload/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.module
Implementation of hook_nodeapi().

File

modules/upload.module, line 646
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);
}