description = Make the most recent version of a file always retain its original filename, older file with the same name are renamed by drupal standards "_0, _1, etc"
core = 7.x
files[] = upload_replace.module
; patched with http://drupal.org/files/upload_replace_error-1115484-13.patch
drupal_set_message(t('The file %old could not be moved to %new',array('%old'=>$tmp_destination,'%new'=>$old_destination)),'error');
return;
}
//move blocking file was successful, update the DB with the actual location after file copy, so we use tmp_destination as it was updated during the move
db_update('file_managed')
->fields(array('uri'=>$old_destination))
->condition('fid',$blocking_file->fid)
->execute();
}
}
}
//Have to clear the cache because the revision data is cached somewhere
/*
* Find the nids where this file is used
$query = "SELECT DISTINCT id FROM {file_usage} WHERE fid=%d";
$result = db_query($query, $new_file->fid);
while($data = db_fetch_object($result)) {
cache_clear_all("node:$data->id");
}
*/
//This is inefficent, but how can we determine what nodes use this file?
// cache_clear_all('*', 'cache_content', TRUE);
}
/**
* HOOK_file_delete, update the uri in the file object before deleting as we may have altered it above
* @param object $new_file
*/
/*
function upload_replace_file_delete($file) {
$file->uri = db_result(db_query("SELECT uri FROM {file_managed} WHERE fid = %d", $file->fid));