summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBojan Zivanovic2013-08-15 15:15:01 (GMT)
committer Bojan Zivanovic2013-08-15 15:15:01 (GMT)
commit2447a4bd3767420e2d371473796583befce47d74 (patch)
tree4417f6bb1ef51b3b3cd44ba7b3561a8af5e23441
parente42737e2e526f055836afe51f41698aeb2bb4473 (diff)
The hook_file_download_access() implementation is broken, replace it with hook_file_download().
-rw-r--r--commerce_file.module25
1 files changed, 19 insertions, 6 deletions
diff --git a/commerce_file.module b/commerce_file.module
index 93617c8..eb7748e 100644
--- a/commerce_file.module
+++ b/commerce_file.module
@@ -151,20 +151,33 @@ function commerce_file_file_entity_access($op, $file, $account) {
}
/**
- * Implements hook_file_download_access().
+ * Implements hook_file_download().
*
* This access hook is called when a private file is being accessed via the
* system/file callback. Access to licensed files is forbidden here, to
* ensure that the file/%file/download callback is used (which tracks
* download counts and forces the explicit download of a file).
*/
-function commerce_file_file_download_access($file_item, $entity_type, $entity) {
- if ($entity_type == 'commerce_product' && !empty($entity->commerce_file)) {
- $commerce_file_items = field_get_items('commerce_product', $entity, 'commerce_file');
- if (in_array($file_item, $commerce_file_items)) {
- return FALSE;
+function commerce_file_file_download($uri) {
+ $files = file_load_multiple(array(), array('uri' => $uri));
+ if (count($files)) {
+ foreach ($files as $item) {
+ // Since some database servers sometimes use a case-insensitive comparison
+ // by default, double check that the filename is an exact match.
+ if ($item->uri === $uri) {
+ $file = $item;
+ break;
+ }
}
}
+ if (!isset($file)) {
+ return;
+ }
+
+ // If the file is licensable, don't allow it to be downloaded this way.
+ if (commerce_file_is_licensable($file)) {
+ return -1;
+ }
}
/**