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?

Comments

aclight’s picture

That 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.

dww’s picture

Status: Active » Needs review
StatusFileSize
new765 bytes
new1.44 KB

Indeed, pretty easy. ;)

You can see it in action if you put this in project_release.module:

/**
 * Implement hook_project_release_download().
 */
function project_release_project_release_download($nid, $filepath, $uid) {
  watchdog('project_release_download', 'Downloaded nid: @nid, uid: @uid, file: @filepath', array('@nid' => $nid, '@uid' => $uid, '@filepath' => $filepath));
}

Resulted in the following on my test site:

Message	Downloaded nid: 11, uid: 1, file: themes/fusion_minimalist_pro-6.x-1.0-alpha2.tar.gz

All of that's true... ;)

dww’s picture

Hrm, 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.

dww’s picture

Status: Needs review » Fixed

Committed #2 to HEAD.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.