Download & Extend

Invoke a hook whenever a private release file download happens.

Project:Project
Version:6.x-1.x-dev
Component:Releases
Category:feature request
Priority:normal
Assigned:dww
Status:closed (fixed)

Issue Summary

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:

<?php
/**
* 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

#1

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.

#2

Status:active» needs review

Indeed, pretty easy. ;)

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

<?php
/**
* 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... ;)
AttachmentSizeStatusTest resultOperations
537576-1.hook_project_release_download.patch1.44 KBIgnored: Check issue status.NoneNone
537576-1.hook_project_release_download.test-implementation.patch765 bytesIgnored: Check issue status.NoneNone

#3

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.

#4

Status:needs review» fixed

Committed #2 to HEAD.

#5

Status:fixed» closed (fixed)

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

nobody click here