Replacement for uc_file

Contrib type: 
Module
Status: 
Uploaded for testing
Moderation: 
Limited approval

Downloads

Compatibility: 
Ubercart 2.x

Massive restructuring of the uc_file module, implementing all functionality in Drupal 5, plus some extras. Information about new features are avilable in CHANGELOG.txt.

I appreciate you testing and reporting bugs... Thanks!

* behaviors used in place of onclick attributes where possible.
* replaced haphazard update/remove calls with one 'refresh' call to prune and update the file list at once where required.
* pruning files that no longer exist now clean up all db tables, including product feature stuff, etc.
* checks for unlink/rmdir now to ensure deletions worked properly. status messages updated accordingly.
* db tables only removed now if files/dirs were successfully removed.
* get_dir_file_ids needed to use regex or else dealing with a structure like 'something/something'
(child dir same name as parent) could fail, due to str_replace replacing all instances it encounters.
* implemented Check all / Uncheck all on file deletion page.
* implemented JS behavior to update the affected file list when clicking the recursion checkbox.
* not showing the recursion checkbox/affected file list on the file deletion form if there isn't any directories in the list.
* added the resume support.

10/13/2008

* Changed _uc_file_retrieve_file_by_* to _uc_file_get_by_* and added a local cache to speed up performance with many files.
* Changed 'File downloads' fieldset on user profile edit page to 'Ubercart file downloads'.
* Not showing the add.remove dialog on the user account edit page, if there are no files to add/remove.
* Added a message at the user account edit page to inform users where to go to add files for download.
* File autocompletion sorts the candidiates first before returning.

10/14/2008

* Small logic cleanup.
* Fixed pager query logic.
* Improved the way file selection happens with file actions.

10/15/2008

* Cleared up the multi-step form even more; now instead of swtching in each phase of the step, the validate/submit handlers are
set in the first phase, so that each can be separated properly.
* Lots of API tightening, fleshed out the doxygen commenting... UI tweaks and improvements.

10/16/2008 (thanks to sratay http://www.ubercart.org/user/3843)

* Getting a PHP warning about the argument to foreach when there were no files uploaded
* Confirmation message for an uploaded file contained the name of the temp file (which could contain a suffix
if uploading the same file more than once)
* No validation for having to select at least one value when trying to delete files (which ended up causing
some errors down the road)

10/20/2008

* Had a bug where I was using assignment instead of comparator...
* Added primary keys to file_users, and file_products
* Made sure in update_6003 that quantity is set to a valid number.

10/21/2008

* Added a toggle in the product administration settings to warn about duplicate file purchases (default to TRUE).
* Added fields download_limit, address_limit, time_granularity, time_quantity to uc_file_products.
* Added fields download_limit, address_limit, expiration to uc_file_users.
* Added support for overriding access limits at the product feature level, as well as the user level.

10/22/2008

* Added the UI at user account page for file adding/removing to a user... also limit adjusting.
* Limits are propagating correctly.
* Added a workaround for a drupal_write_record() bug...
* Upgrade path now adds expiration fiel to uc_file_users, and calculates it from the granted field.

10/23/2008

* Tweaks and polish and commenting all over...
* Expiration on user account page can now be set to 'never', behaviors implemented for them.
* Conditional Actions interface, don't set the desired order status to fire download updates anymore, specify
it in the CA admin interface. At trigger "Order status gets updated", predicate "Renew purchased files".

10/30/2008

* drupal_write_record() seems unreliable on the upgrade path from 5 -> 6, so it was replaced.

11/10/2008

* The file downloads page wasn't showing the first associated product feature like it should have been.
* The $cache variable in uc_file_get_by_key() shuld have been defined as global, not static (thanks Lyle)


PreviewAttachmentSize
uc_file.zip34.89 KB
sratay's picture
Offline
Joined: 10/07/2008
Juice: 2
A few small changes to admin portion

I tested out all the admin functionality and it looks great. I ran into the following issues that I have resolved in the attached code.

* Getting a PHP warning about the argument to foreach when there were no files uploaded
* Confirmation message for an uploaded file contained the name of the temp file (which could contain a suffix if uploading the same file more than once)
* No validation for having to select at least one value when trying to delete files (which ended up causing some errors down the road)

AttachmentSize
uc_file.zip 29.34 KB
cha0s's picture
Offline
Getting busy with the Ubercode.
Joined: 08/22/2008
Juice: 416
Thanks =)

Thanks! I got it incorporated into the zip on the first post. I changed is_array() to an array cast (personal preference), and made the one-line if use {} (Drupal standards).

Try FreeBASIC!
My game Lynn's Legacy

cha0s's picture
Offline
Getting busy with the Ubercode.
Joined: 08/22/2008
Juice: 416
Re: Replacement for uc_file

Bump! I implemented limit accumulation on users now... so instead of someone ever getting a duplicate file, the download/address/time limits will just accumulate on the same file.

NOTE: You should manually remove any duplicate files within a user's privilege list. Having multiple files attached is at this point undefined. There is no reasonable way to automate this so please make sure that you back up your site before you apply this, and remove the duplicates.

New interface at the User account page for adjustig and adding/removing files to a specific user. New stuff at the features tab of a product, allowing you to override the global limits.

Moved the hook_order stuff out into its own function so interfacing with CA for recurring file renewals should be a breeze now. I still have to learn a bit about interfacing with CA though...

Oh, and I threw in some unit tests Smiling It isn't total complete lockdown coverage, but it's good. You'll need this file: http://cha0s.selfip.org/dev/ubercart/ubercart_web_test_case.inc and you put it in sites/all/modules/ubercart/test (or wherever your Ubercart folder is at...)

Have fun! I'd appreciate suggestions about how to streamline the UI at the user account page...

Try FreeBASIC!
My game Lynn's Legacy

cha0s's picture
Offline
Getting busy with the Ubercode.
Joined: 08/22/2008
Juice: 416
Re: Re: Replacement for uc_file

Bumpy... after having a conversation with a guy at DCC I realized my expiration calcs sucked, so I fixed them. Also I accidentally cut out one of the main functions out of this last release, so it probably didn't work at all :S I got it back in there, with some new unit tests for expiration calculation and also limit overrides.

Enjoi! Please test! Smiling

Try FreeBASIC!
My game Lynn's Legacy

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4111
Re: Re: Re: Replacement for uc_file

Suggestion for the accumulated limits on duplicate files, would it be possible to only apply that to the first record found for that user? On our site, multiple files is almost a guarantee (with a good number of customers "forgetting" they own a certain product and re-purchasing it later by mistake).. so needless to say, going through thousands of customers isn't exactly a simple task, although in theory there could be a query written that would do user-by-user comparisons. Possibly break it up into x number of compares per cron job or something.

Just a thought.

--
Help directly fund development: Donate via PayPal!

stephthegeek's picture
Offline
Theminator
Joined: 10/20/2007
Juice: 575
Re: Re: Re: Re: Replacement for uc_file

Actually we had a chat about this and I brought up the possible situation of wanting to accumulate these limits. For example, while we offer lifetime access to any file download purchased, I could conceive of a situation where you were really buying a "subscription" to the file and would want to be able to extend the existing access period rather than replace it.

Unless you're just talking about this as an optional feature Smiling

Gorgeous original Drupal themes (and Ubercart themes!) ~ Psst: more Ubercart themes on our new site

cha0s's picture
Offline
Getting busy with the Ubercode.
Joined: 08/22/2008
Juice: 416
Re: Re: Re: Re: Replacement for uc_file

I'm not sure because I haven't tested it. Duplicate files do not make sense at all. You will never ever need more than one record of a user having permissions to download files. If you're selling one month and they have 10 days left, it's only fair that they'll have 40 days if they buy it again. (assuming the month is 30 days)

That said, the code probably WILL do just that (operate on the first result from the db). Like I said though, I haven't tested it because starting from now, dupes are a thing of the past.

Try FreeBASIC!
My game Lynn's Legacy