Closed (fixed)
Project:
UC Gift Certificate
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
7 Sep 2009 at 22:18 UTC
Updated:
29 Dec 2010 at 17:50 UTC
Jump to comment: Most recent file
Comments
Comment #1
aasarava commentedI noticed the same problem, so I looked at the code. Turns out there's a bug in uc_gift_certificate.admin.inc at line 204. It should be loading the recipient, but loads the purchaser instead.
And then when the module calls its function to email the recipient, the function has a bad side effect of updating the record so that the user_id is updated with the wrong info that was loaded earlier.
To fix the immediate problem, change line 204 in uc_gift_certificate.admin.inc like so:
OLD:
NEW:
As for the mail function that updates the record, I'm not entirely sure why that's necessary. Can one of the module maintainers weigh in? It seems dangerous to have an unintended update like that in what is assumed to be a simple mail function.
Comment #2
jrust commentedThanks, fix is checked into dev. aasarava, could you elaborate more on the it updating the user record in the mail function? From what I can tell it will only ever call user_save() when it is creating a new user record.
Comment #3
jrust commentedComment #4
aasarava commentedjrust, when I say the mail function has a side effect of updating the certificate record, I am referring to line 185 in uc_gift_certificate.module:
This update happens in the function uc_gift_certificate_mail_cert_notice(). The reason I think this is strange is because the function is supposed to be responsible for mailing out a certificate, and not anything else. So the update is a "side effect". As a developer, I was surprised and frustrated to find this update taking place inside the mail function when I was debugging the earlier issue mentioned in this thread. And I'm still not sure why this update is taking place.
If the update is necessary, it would be good to remove it from the mail function and put it in its own function, and then to document the reason for doing it.
Comment #5
torgospizzaYou're right, the two functionalities should be split. This is kind of a holdover from when the module was first written, way back. I'll add it to my task list.
EDIT: Nevermind, it is required because if you're creating a new user, you need the certificate to be assigned to the newly-created user, correct? I could change that long PHP line into just:
because that does the same thing and will be easier to update. But I think it's impossible to avoid needing to update the certificate with the new userid. Unless I'm missing something?
EDIT again: Indeed, I am confusing two separate issues. The issue is really the dual functionality. User creation should move into its own function. I'll submit a patch that will refactor this code soon.
Comment #6
torgospizzaHere is a patch for the first part of the process. (Changing it into a function, and the new function added to the user.inc file.)
Comment #7
jrust commentedFixed in CVS: Split out the issuing of a certificate from sending it