Closed (fixed)
Project:
e-Commerce
Version:
master
Component:
file
Priority:
Minor
Category:
Feature request
Assigned:
Reporter:
Created:
10 May 2006 at 21:40 UTC
Updated:
20 Aug 2008 at 16:49 UTC
Jump to comment: Most recent file
Following up previous discussions on this topic, here is a patch the makes it possible to turn audio nodes into products.
Summary:
To test, you'll have to install the DRUPAL-4-7 version of audio module, and of course ecommerce module. Then apply the patch (from the drupal root dir, assumes both modules are installed into modules/). Create audio node(s). Use product_to_product to convert audio nodes into file products. Then log in as unprivileged user. Notice that play and download links disappear from audio nodes. Purchase the nodes. Set payment status on transaction to paid. Now the user will be able to play/download the files.
| Comment | File | Size | Author |
|---|---|---|---|
| #26 | ec_media.module | 3.41 KB | Dave Cohen |
| #24 | 62906.patch_2.txt | 11.72 KB | Dave Cohen |
| #21 | 62906.patch_1.txt | 11.65 KB | Dave Cohen |
| #20 | 62906.patch_0.txt | 11.35 KB | Dave Cohen |
| #12 | 62906.patch.txt | 15.15 KB | Dave Cohen |
Comments
Comment #1
robin monks commentedI tried out your patch, and overall it looks good. Although, I did get this warning on audio pages as annonymous after appling the patch:
I'd be happy to try to debug this further.
Robin
I ♥ Bugz
Comment #2
Dave Cohen commentedNot my fault!
http://drupal.org/node/62670
Comment #3
Dave Cohen commentedYes my fault!
But its a problem in another patch of mine you've installed, namely product_transform. I will fix. D'oh!
Comment #4
robin monks commentedHeh, thanks for tracking down that error :)
Also, another problem with the patch. It's not at all secure for the seller of the audio files. For example:
http://ecommerce.civicspacelabs.com/?q=audio/play/17 ogg
http://ecommerce.civicspacelabs.com/?q=audio/play/16 wma
http://ecommerce.civicspacelabs.com/?q=audio/play/12 mp3
http://ecommerce.civicspacelabs.com/?q=node/17
http://ecommerce.civicspacelabs.com/?q=node/16
http://ecommerce.civicspacelabs.com/?q=node/12
Any file, no matter the price or purchase status can be downloaded in that form. As you can see from the node links, that shouldn't happen. The solution (IMHO) is some sort of hash or sessid passed to the play URLs that:
a) Checks to make sure the person can access the file.
b) Expires after X minutes.
c) Plays a user defined music file should the user not be supposed to download the file.
These are just some "top 'o me head" thoughts, it might be solvable much easier.
Robin
Comment #5
drewish commentedHere's the link in to the relevant issue in the audio module tracker: http://drupal.org/node/33708
Comment #6
drewish commentedto follow up on what robin said, the proposed patch just hides the links it doesn't affect the callback function. the last patch i attached to #33708 implements the permissions checks correctly but uses an hook_audio interface rather than the one that yogadex developed.
Comment #7
Dave Cohen commentedHere is a patch taking into account hook_audio. Hook_audio is detailed here: http://drupal.org/node/33708. It seems likely that the audio folks will check that in, although I can't say when.
So now audio has an audio-specific API, and file.module has an ecommerce file API (which I would like to see adopted as a Drupal standard, but that may never happen). So to bridge the interfaces between the two, I've created a module called ec_media. While in this patch ec_media deals only with the audio API, the idea is that when video and other modules invent their own file api like audio has done, we can add code to ec_media to make the various nodes into well behaved products.
If there is violent opposition to the idea of creating a new module, we can of course move that code into file.module.
To install the patch:
1) patch audio.module with audio_33708.patch
2) patch file.module with file_62906.patch
3) install and enable ecommerce/contrib/ec_media/ec_media.module
To configure:
1) go to admin/settings/content-types/audio
2) set the product type to 'file download' and save
Now each audio node can be a product.
Comment #8
simeHi Yogadex
This looks really cool. The tags stuff worked great and I love the Play button. Here is some feedback.
1. I couldn't manage to make this become a product. Do I need the product patch as well? There was no product tab anyway.
2. When the file is too big, there is a misleading message. when_file_too_big.gif
3. When I create the node and upload a file. I get an error if there is a directory problem, but it still looks like it went OK. Ie. I have an audio node, but no corresponding file. It is also very misleading because you get the tags out, so it really does seem like the file has been uploaded. I think you should discard the tags when the upload fails. on_creation.gif & how_download_list.gif show this.
4. warning: implode() [function.implode]: Bad arguments. ......on line 473.
after_normal_creation.gif
Comment #9
Dave Cohen commentedSime,
If you have the product patch, which I suspect you do, you have to do this:
1) go to admin/settings/content-types/audio
2) set the product type to 'file download' and save
only then can you make the audio nodes into products.
The other problems you report exist in the audio module. They are not specific to the changes I made. You can avoid those problems with proper configuration, but I agree that the errors could be handled better.
Comment #10
simeOK, well, seems ok but can't say more until the audio patches.
Comment #11
drewish commentedjust wanted to note that the changes to the audio module have been committed.
Comment #12
Dave Cohen commentedUpdated patch includes help text for ec_media. Compatible with latest changes checked into audio module.
Apply this patch from the ecommerce directory. Enable both file module and ec_media module. Follow instruction under admin >> help >> ec_media. (The help text assumes http://drupal.org/node/62682, if you do not have, skip the audio node type config step).
(Again, if people prefer ec_media code to be rolled into file.module, let me know and I will do that).
Marking as ready to be committed. If you disagree, please follow up. Thanks.
Comment #13
gordon commentedSomeone else besides the author needs to test the code before it can be commited.
Comment #14
robin monks commentedTested on a PHP4 site with Drupal 4.7. Works like a charm.
+1
Robin
Comment #15
marlowx commentedthis all looks really good...
here are some more "top of my head" type things that struck me...
can you still allow people to press play and stream audio to sample it?
what would be very very cool, is that if someone hasn't purchased the song or perhaps hasn't registered to the site, that they can only listen to the first "X" seconds (admin definable?) of the song?
because it would be nice to prevue the song before buying all in one interface...
it would be nice to allow a "free" download or two to registered users...
-- streamable to everybody (whole song streams)
-- stream first (insert value here) seconds to --- annonymos user --- registered user
-- downloable to --- annonymous user --- registered user --- purchase only
-- stream quality ---64 ---128 ---192 | download quality:---64 ---128 ---192 ---320
(or support 2 files for different quality? - some bands choose to sell the higher quality mp3 and give free downloads of lower quality mp3 for samples etc)
-----
just a few ideas!
Comment #16
Dublin Drupaller commentedgreat patch idea..
Just tried it with Drupal 4.7 and it seems to work except for the following error on the PRODUCT page:
warning: in_array(): Wrong datatype for second argument in /modules/ecommerce/product/product.module on line 610.Am happy to help debug further...and am looking at the product module now to see if I can fix it myself...thought I'd post up here in case others are trying it.
Dub
Comment #17
Dave Cohen commentedIn my version, the call to in_array() is on line 615. Do you have the latest? In your file, is the call in product_add()?
Do you have any product types enabled? If not, enabling any should make the problem go away. But should be easy to add a check in the code, too. Something like this (I have not tested)
Comment #18
Dave Cohen commentedThis is a good idea, but sounds like a feature request to audio module. Each audio node could have a full version and a sample version (short, less quality, or both).
You could of course set a product's price to $0.0, but that's not really what you want. You could create samples which are audio nodes, but do _not_ make them products. The problem then is the files will not be downloadable by normal users. But you solve that by implementing hook_audio in a module you define. In that hook place some logic that permits the download (returns TRUE) only for your free sample nodes. Requires some coding, but not hard.
Comment #19
Dave Cohen commentedSorry, I have at least one other patch installed(http://drupal.org/node/62682). It's no surprise the line numbers are not the same.
Comment #20
Dave Cohen commentedI've rerolled the patch against the latest file.module
Note that this patch REQUIRES http://drupal.org/node/62682. Without that patch, there is a problem when you first create the audio node, then convert it into a product using the product tab. At this point the file module is unaware of the file path, and it will not be notified until the node itself is saved.
If it is necessary to implement this without the dependency on #62683, please let me know. (That is, if that patch will not be accepted.)
Comment #21
Dave Cohen commentedThis update gets around the dependency on #62682. It does this by saving the filepath to ec_product_file table when the node is created, even if it is not yet a product. If the node is never converted to a product, this is an unecessary row in the database. however if it is later converted into a product the information will be up-to-date.
Works with either the product tab, or with patch #62682 installed.
Comment #22
zirafa commentedHey yogadex,
Thanks for all your hard work on this! Do you think you could explain or point to some info about how what's going on with the FileAPI stuff here and your thoughts/methods behind it? This might help Gregory get this patch in, and help explain your motives. This will be awesome functionality to get in e-commerce though!
-Farsheed
Comment #23
Dave Cohen commentedThe idea behind this patch is to allow an audio node to be a product. In general, any type of node can be transformed into a product. however nodes that handle files, like the audio node, need some special treatment.
This patch tries to address the problem in a generic way. So that any node type which manages a file can become a file product. It also contains some code specific to audio nodes. (The code specific to the audio type is in a module called ec_media, while the generic parts are in file.module).
The file apis accomplish 2 things. First, file module implements a hook, file_ec_file_event(), which lets the file module know when files are updated. It keeps the ec_product_file table up-to-date.
Second, file module implements file_ec_file_access(). This allows the file.module to control access to files which are products. So the audio module will not allow a download unless the file module allows it. That is, only when a user has purchased the file.
Originally, I proposed these hooks as a drupal-wide file api. That idea did not get very far. The audio module developers preferred to design their own API. So my original hook names of hook_file_event and hook_file_access I changed to hook_ec_file_event and hook_ec_file_access (ec for ecommerce). The parameters passed into those methods are designed to support any files managed by any modules.
Because audio implemented a different API on it's end, I needed some code to bridge the two APIs. Rather than put audio-specific code into file.module, I put it in contrib/ec_media/ec_media.module. The idea being that when other file-managing nodes need to be productized, more code may be added to ec_media to support it. (Or even better, a module could implement the ec file api on its own. Any module implementing hook_ec_file_nodetypes() will be recognized by the file.module.)
To use this patch you must configure the audio module and file module (and all dependencies). Then set up permissions so the average user cannot download or play audio files. Next create audio nodes, and transform them into file products. Now, the average user can download those audio files only after they can purchased (and paid for) the files.
Comment #24
Dave Cohen commentedThis version fixes a bug when both this patch and 62682 are installed. There was a problem creating new nodes this fixes it without significant changes to the code.
Comment #25
gordon commentedThis has been commited, but the ec_media needs to be added to contrib.
Comment #26
Dave Cohen commentedSorry, I thought I had included ec_media in the patch file. Attaching it again. I don't have permission to add it myself.
Comment #27
simeHi yogadex
This has been committed to 4.7 and CVS which is great. For the README:
- you are the original author?
- you will be actively supporting this module?
Comment #28
(not verified) commentedComment #29
tuklu_san commentedHi,
I downloaded Drupal 4.7, Audio and eCommerce for Drupal 4.7, and tried to apply the patch, and get the following.
Is this right ? I wonder why the patch program can't see the files even when they are apparently there, and so many hunks are failing.
Here is what I installed and what I get:
audio-4.7.x-1.0.tar.gz
drupal-4.7.0.tar.gz
ecommerce-4.7.x-3.4.tar.gz
bash-3.00$ patch -b -u < mp3_product.patch.txt
can't find file to patch at input line 10
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|? modules/ecommerce/product_transform
|? modules/audio/getid3
|Index: modules/ecommerce/file/file.module
|===================================================================
|RCS file: /cvs/drupal-contrib/contributions/modules/ecommerce/file/file.module,v
|retrieving revision 1.36
|diff -u -u -F^f -r1.36 file.module
|--- modules/ecommerce/file/file.module 29 Apr 2006 05:07:00 -0000 1.36
|+++ modules/ecommerce/file/file.module 10 May 2006 21:26:12 -0000
--------------------------
File to patch:
bash-3.00$ ls modules/ecommerce/file
README.txt file.install file.module po
bash-3.00$ patch -b -u < mp3_product.patch.txt
can't find file to patch at input line 10
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|? modules/ecommerce/product_transform
|? modules/audio/getid3
|Index: modules/ecommerce/file/file.module
|===================================================================
|RCS file: /cvs/drupal-contrib/contributions/modules/ecommerce/file/file.module,v
|retrieving revision 1.36
|diff -u -u -F^f -r1.36 file.module
|--- modules/ecommerce/file/file.module 29 Apr 2006 05:07:00 -0000 1.36
|+++ modules/ecommerce/file/file.module 10 May 2006 21:26:12 -0000
--------------------------
File to patch: modules/ecommerce/file/file.module
patching file modules/ecommerce/file/file.module
Hunk #1 FAILED at 142.
Hunk #2 FAILED at 158.
Hunk #3 FAILED at 174.
Hunk #4 FAILED at 451.
Hunk #5 FAILED at 496.
Hunk #6 FAILED at 555.
6 out of 6 hunks FAILED -- saving rejects to file modules/ecommerce/file/file.module.rej
can't find file to patch at input line 204
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|Index: modules/ecommerce/product/product.module
|===================================================================
|RCS file: /cvs/drupal-contrib/contributions/modules/ecommerce/product/product.module,v
|retrieving revision 1.108
|diff -u -u -F^f -r1.108 product.module
|--- modules/ecommerce/product/product.module 8 May 2006 11:56:14 -0000 1.108
|+++ modules/ecommerce/product/product.module 10 May 2006 21:26:13 -0000
--------------------------
File to patch: modules/ecommerce/product/product.module
patching file modules/ecommerce/product/product.module
Hunk #1 FAILED at 730.
1 out of 1 hunk FAILED -- saving rejects to file modules/ecommerce/product/product.module.rej
can't find file to patch at input line 225
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|Index: modules/audio/audio.module
|===================================================================
|RCS file: /cvs/drupal-contrib/contributions/modules/audio/audio.module,v
|retrieving revision 1.51
|diff -u -u -F^f -r1.51 audio.module
|--- modules/audio/audio.module 21 Apr 2006 21:46:10 -0000 1.51
|+++ modules/audio/audio.module 10 May 2006 21:26:15 -0000
--------------------------
File to patch: modules/audio/audio.module
patching file modules/audio/audio.module
Hunk #1 FAILED at 130.
Hunk #2 FAILED at 180.
Hunk #3 succeeded at 475 (offset 131 lines).
Hunk #4 succeeded at 519 (offset 129 lines).
Hunk #5 succeeded at 565 (offset 120 lines).
Hunk #6 succeeded at 586 (offset 122 lines).
Hunk #7 succeeded at 605 (offset 126 lines).
Hunk #8 FAILED at 1269.
Hunk #9 succeeded at 1748 (offset 207 lines).
3 out of 9 hunks FAILED -- saving rejects to file modules/audio/audio.module.rej
Thank you!
Comment #30
tuklu_san commentedI was told to try -p0 and patch does find the files now. However, I tried the patch on 4.7.0 and 4.7.11 cores with the same modules as the previous post, and still get a bunch of failures :(
4.7.0:
bash-3.00$ patch -u -b -p0 < mp3_product.patch.txt
patching file modules/ecommerce/file/file.module
Hunk #1 FAILED at 142.
Hunk #2 FAILED at 158.
Hunk #3 FAILED at 174.
Hunk #4 FAILED at 451.
Hunk #5 FAILED at 496.
Hunk #6 FAILED at 555.
6 out of 6 hunks FAILED -- saving rejects to file modules/ecommerce/file/file.module.rej
patching file modules/ecommerce/product/product.module
Hunk #1 FAILED at 730.
1 out of 1 hunk FAILED -- saving rejects to file modules/ecommerce/product/product.module.rej
patching file modules/audio/audio.module
Hunk #1 FAILED at 130.
Hunk #2 FAILED at 180.
Hunk #3 succeeded at 475 (offset 131 lines).
Hunk #4 succeeded at 519 (offset 129 lines).
Hunk #5 succeeded at 565 (offset 120 lines).
Hunk #6 succeeded at 586 (offset 122 lines).
Hunk #7 succeeded at 605 (offset 126 lines).
Hunk #8 FAILED at 1269.
Hunk #9 succeeded at 1748 (offset 207 lines).
3 out of 9 hunks FAILED -- saving rejects to file modules/audio/audio.module.rej
4.7.11:
bash-3.00$ patch -u -b -p0 < mp3_product.patch.txt
patching file modules/ecommerce/file/file.module
Hunk #1 FAILED at 142.
Hunk #2 FAILED at 158.
Hunk #3 FAILED at 174.
Hunk #4 FAILED at 451.
Hunk #5 FAILED at 496.
Hunk #6 FAILED at 555.
6 out of 6 hunks FAILED -- saving rejects to file modules/ecommerce/file/file.module.rej
patching file modules/ecommerce/product/product.module
Hunk #1 FAILED at 730.
1 out of 1 hunk FAILED -- saving rejects to file modules/ecommerce/product/product.module.rej
patching file modules/audio/audio.module
Hunk #1 FAILED at 130.
Hunk #2 FAILED at 180.
Hunk #3 succeeded at 475 (offset 131 lines).
Hunk #4 succeeded at 519 (offset 129 lines).
Hunk #5 succeeded at 565 (offset 120 lines).
Hunk #6 succeeded at 586 (offset 122 lines).
Hunk #7 succeeded at 605 (offset 126 lines).
Hunk #8 FAILED at 1269.
Hunk #9 succeeded at 1748 (offset 207 lines).
3 out of 9 hunks FAILED -- saving rejects to file modules/audio/audio.module.rej
Thanks!