Follow-up from #537268: Provide mechanism for private downloads of release node files on sites with public file access. It'd be nice to invoke a hook whenever that script is going to serve a real file, for example, to allow a module to count downloads for each file/release/project, etc.
I'm thinking:
/**
* Hook invoked whenever a private file is downloaded from a release node.
*
* @param $nid
* The node ID of the release node the file was downloaded from.
* @param $filepath
* The {files}.filepath of the downloaded file.
* @param $uid
* The user ID of the user who downloaded the file.
*
* @see project-release-private-download.php
*/
hook_project_release_download($nid, $filepath, $uid) {
}
Should be a trivial patch. Any objections to this API?
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 537576-1.hook_project_release_download.patch | 1.44 KB | dww |
| #2 | 537576-1.hook_project_release_download.test-implementation.patch | 765 bytes | dww |
Comments
Comment #1
aclight commentedThat sounds good to me. One thing to think about--should hook_file_download be invoked at all when a file is being downloaded this way? Probably not, since I guess this isn't "officially" a private download of a file, but just thinking aloud.
Comment #2
dwwIndeed, pretty easy. ;)
You can see it in action if you put this in project_release.module:
Resulted in the following on my test site:
All of that's true... ;)
Comment #3
dwwHrm, looks like http://api.drupal.org/api/function/hook_file_download/6 isn't really what we want to happen here. I'd rather not, especially since yeah, this isn't the core private download system.
Comment #4
dwwCommitted #2 to HEAD.