diff --git a/commerce_file.module b/commerce_file.module index 93617c865f99eb35bf740614b275efd9c1dc087b..eb7748ef42f301fef0497c57e2356fd1b29a806d 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; + } } /**