When you purchase a license for a file the first time, its granted and actual download count is displayed at the customer's Files user area (at user/[UID]/my-files). For example: 1/10 when the file has been download 1 time out of 10 possible times.

When the same user purchases the same file later, it gets displayed in addition to the first one, linked to the same download link, with the expiration date later than the original's one, but its download counter re-credited to 0/10. See the attached screenshot 1.

Subsequent downloads will only increment the original counter. See the attached screenshot 2.

When the original file's download limit is reached (10/10), no more downloads will be possible, even for the newly purchased file that should still have all 10 downloads possible. See the attached screenshot 3.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Tyler the Creator’s picture

I'm looking into this issue (or at least a similar one) on one of my current projects. The module is coded with the intention of only having 1 active license per product. If the user manages to buy more than 1 license of the same product, the module grabs the first license it finds and ignores the rest. Meaning when it comes time for the module to check if a file should be downloadable, it grabs the same license for both and checks the download limit on just that 1 license, making both files either downloadable or not.

I'm trying to make a patch to fix this functionality, I'll upload it once I figure out an elegant solution.

bojanz’s picture

I'm not convinced it makes sense to have multiple active licenses for the same file.
A better approach might be to simply forbid that.

Tyler the Creator’s picture

With our project, we want to use something of an "honour system". A user can certainly buy a license to a file, and then distribute that file to as many people as they want once they've downloaded it, but we hope that if a user wants 30 files, they would buy 30 licenses. In that case, a user would need 30 different active licenses (at least until they're downloaded) for the same file.

Also as the module works right now, once a file hits it's download limit, if a user went to buy a new license for that same file, the commerce_file_can_download function is still grabbing the license that has already hit the limit, so the new file can't be downloaded.

You can certainly let me know if these scenarios aren't what the module is intended for, and I can try to find another solution.

roball’s picture

Imagine the case when you have set the download limit to 1 (one time) and no expiration. After a customer has bought the license and downloaded the file, he will never ever be able to download the file again, even if he purchases it again years later.

bojanz’s picture

Okay, let's fix that properly then.
I won't have time for this bug in the upcoming days, so a patch would be helpful.

roball’s picture

Great to hear you agree, bojanz that there may be scenarios where it indeed makes sense to purchase the same file more than once. Another example is when a file will be replaced by a newer, enhanced version, which customers may want to purchase as well.

Interested in the patch Tyler Pepper announced to try rolling out.

Tyler the Creator’s picture

I believe I have it working correctly, I added some code to pass the license_id on the file's views row to the formatter, and if the license_id isn't part of the view it just falls back to the original code (though that shouldn't really happen, since the download limit field on the view is also assuming that the license_id field is in the view). I also fixed a problem where clicking on a file belonging to 1 license would mark another as downloaded by passing the license_id into the file download url query, and making sure that the download token was distinct to each license_id.

Let me know if this works for you.

I patched both 7.x-2.x-dev and 7.x-2.0-beta2.

Tyler the Creator’s picture

Status: Active » Needs review

Marked for review.

roball’s picture

Status: Needs review » Reviewed & tested by the community

Tyler Pepper, thanks a lot! Your patch commerce_file-allow_multiple_active_licenses_per_file-2215357-7-7.x_2.x_dev.patch from #7 is working perfectly for me! FYI, it can also be applied against the stock 7.x-2.0-beta2 release.

roball’s picture

The attached screenshot shows how the My Files section looks now (after applying your patch) :-)

Tyler the Creator’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
5.65 KB

I have to open this back up for review since one of my co-workers QA'd our project and found a bug where a user could download a file with multiple licenses indefinitely until the page was reloaded. The new patch contains everything from before, plus a check to reload the page once the download limit is hit, while displaying a Drupal error message. The patch also changes the original direct to 403 page functionality to the same page reload & Drupal error message when trying to download a file with 1 license multiple times passed the download limit.

roball’s picture

Status: Needs review » Reviewed & tested by the community

Tyler Pepper, thanks a lot! I very much like the automatically loading of the my-files page once the download limit has been reached, with the error message. I think the wording 'Please purchase more downloads from the store.' may be better renamed in something like 'If you need more downloads, you may want to purchase another license.'

roball’s picture

Status: Reviewed & tested by the community » Needs work

Sorry, just found a bug:

Although the my-files page perfectly displays the different purchases of the same file perfectly, the Checkout complete page a customer will see directly after completing the payment doesn't if you have purchased a file in the past and already hit its download limit. When you purchase the file again, the Checkout complete page only contains references to the very first purchased file. Since that one no more has a download grant, they will display without any download link.

Tyler the Creator’s picture

Oh ok, I assume that's with the License information and License completion message checkout panes enabled? That's probably why I missed it (both are disabled on my project at the moment). Thanks for picking that up!

roball’s picture

I have the License completion message pane enabled on the Checkout complete page. The License information is kept Disabled, since it did not seem to provide any information.

You can see the attached screenshot how my Checkout complete screen looks. I have purchased the same file twice. It was already purchased earlier and its download limit has been reached. Thanks for your work on it!

I think it would also be useful to see in the Checkout complete screen how many times each purchased file can be downloaded.

roball’s picture

In addition to the problem reported in #13, the patch from #11 introduces another problem:
Each time the admin visits admin/commerce/licenses the dblog logs the following two PHP notices per licensed file:

Trying to get property of non-object in theme_commerce_file_download_link() (line 876 of /etc/drupal7/all/modules/commerce_file/commerce_file.module).

and

Trying to get property of non-object in theme_commerce_file_download_link() (line 877 of /etc/drupal7/all/modules/commerce_file/commerce_file.module).

After reverting the patch these errors no more occurred.

Tyler the Creator’s picture

Thanks for catching these problems! I can understand how certain things work in 1 project but not another due to minute differences in the configs. Here's a new patch. I couldn't get the dblogs to show your error but I think I managed to fix it. Let me know!

roball’s picture

Status: Needs review » Reviewed & tested by the community

Thank you very much for the revised patch - now everything seems to work perfect! File links display fine on the License completion message pane, and there are no more PHP notices. Would be nice to get this committed.

roball’s picture

bojanz, do you think you will find some time to review Tyler Pepper's patch from #17? It is working fine for me.

Thanks!

roball’s picture

Version: 7.x-2.0-beta2 » 7.x-2.0-beta3
roball’s picture

Status: Reviewed & tested by the community » Needs work

The patch from #17 no longer applies to the recently released 7.x-2.0-beta3:

[user@server commerce_file]# patch --dry-run -p1 < commerce_file-allow_multiple_active_licenses_per_file-2215357-17-7.x_2.x.patch
patching file commerce_file.module
Hunk #4 succeeded at 604 (offset -26 lines).
Hunk #5 succeeded at 787 (offset -26 lines).
Hunk #6 succeeded at 820 (offset -26 lines).
Hunk #7 succeeded at 877 (offset -26 lines).
Hunk #8 FAILED at 953.
1 out of 8 hunks FAILED -- saving rejects to file commerce_file.module.rej
patching file plugins/license_type/CommerceLicenseFile.class.php
Tyler the Creator’s picture

Nice catch! Try this one.

Funny thing is that I think what was breaking #17's patch was another patch that I made that got committed and released.

Tyler the Creator’s picture

Status: Needs work » Needs review
roball’s picture

Status: Needs review » Reviewed & tested by the community

Perfect - patch #22 works perfectly, thank you.

Now we have to wait for bojanz's decision on committing it.

bojanz’s picture

I'll try to review this soon. It's definitely a release blocker for me.

roball’s picture

Excellent news, thank you bojanz!

drakythe’s picture

I just applied this patch and #2219835: Commerce File Download Limit Hook - Commerce File Bulk so I could use your commerce_file_bulk module, Tyler, and they work great!

This module however introduced a whitespace and file permission issue, so you may want to re-roll it.

The errors I got on applying this patch (after #2219835: Commerce File Download Limit Hook - Commerce File Bulk):
commerce_file-allow_multiple_active_licenses_per_file-2215357-22-7.x_2.x.patch:47: trailing whitespace.

warning: commerce_file.module has type 100755, expected 100644
warning: 1 line adds whitespace errors.

Tyler the Creator’s picture

Hmm I just applied both patches (Download Limit Hook first, then this one) on both 7.x-2.0-beta3 and 7.x-2.x-dev and I couldn't reproduce the whitespace errors. Which version of the module are you using?

drakythe’s picture

Tyler, I was using the dev version, I just tried it again with the Beta-3 and confirmed the error. I've attached a screenshot from vim with whitespace highlighting on this patch (the red bit). Again just to clarify, I applied both of your patches in the order of #2219835: Commerce File Download Limit Hook - Commerce File Bulk Then this one. They apply, but change the file permissions and add a white space, both errors occur on OSX/Linux when applying this patch.

Tyler the Creator’s picture

Oh ok, I see it now. Try this new patch:

pun_pun’s picture

Hello!
Tyler Pepper, thank you for your patch!
I use commerce kickstart (7.x-2.17)+Commerce File 7.x-2.0-beta3 and your patches work only for Checkout pane (CHECKOUT COMPLETE) but in the user profile "files" tab there are inactive links. The same inactive links are in the product list in the shop. I applied patch #30 and #2219835: Commerce File Download Limit Hook - Commerce File Bulk... Maybe I've missed something?
And for anonymous users displays the alarm "This file has hit the download limit. If you would like to continue downloading this file, please purchase more licenses from the store. 404 ERROR Not found" but not "403 error. Access denied" when try to use download link. I think it is not really correct.
Thank you!

pun_pun’s picture

Hello! I think, I found the reason why links are not active for newly purchased additional licenses for the same product. When using more then one licence for the same file the counters do not count downloads for each licence separately (licenses are different, but download link is the same). Any downloads by any licence shows only on the first licence counter until it reaches the download limit (10/10) and then all download links become inactive for all licenses. %)

Tyler the Creator’s picture

Hey pun_pun, I haven't tested my patches with commerce kickstart so it could be working a bit differently than regular commerce for some reason. It's something that I (or someone else in the community) will have to look into when we have time. Hopefully this can get resolved soon as I really hope that these Commerce modules get patched with the new fixes.

pun_pun’s picture

Tyler Pepper, thank you! I'll be waiting for the news. :)

bojanz’s picture

Status: Reviewed & tested by the community » Needs work

This will need to be rerolled / retested now that #2302897: Access token generation changed in file_entity module has been committed.

Tyler the Creator’s picture

New patch attached based on newest version of 7.x-2.x-dev

Tyler the Creator’s picture

Status: Needs work » Needs review
Tyler the Creator’s picture

Wondering if anyone can review this, or if it needs to be rerolled again. It would be nice to get this committed.

Thanks!

Tyler the Creator’s picture

Anyone? :\

DamienMcKenna’s picture

Version: 7.x-2.0-beta3 » 7.x-2.x-dev