Closed (won't fix)
Project:
lm_paypal
Version:
5.x-1.0
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
22 Apr 2009 at 07:18 UTC
Updated:
23 Apr 2009 at 13:45 UTC
I have gotten LM Paypal working nicely with one exception now. It appears this issue:
Was never resolved, as I have noticed during my sandbox tests. I have a premium role that allows access to certain things, which LM_Paypal is doing correctly upon a payment, however, the user badge that I have assigned to that role, which automatically gets added if I manually add the role to a user, is not being added when LM_Paypal assigns the role?
Comments
Comment #1
lyricnz commentedArguably user_badges should be making use of $op=after_update in hook_user($op, $edit, $account, ...) and checking the status of $account - but it's code is actually triggered by $op=update, and looking in the $edit to see what's in the user-edit form. For programatic changes, there is no such form!
But, even if user_badges did this, LM Paypal is not being well behaved anyway - it doesn't send out ANY notifications on this update. So you need to:
- hack LM paypal lm_paypal_user_gain_role() and lm_paypal_user_loose_role() to construct a fake $edit and call hook_user:$op=update - which will NOT save changes requested by other modules (per the contract of hook_update). Note: this could have unexpected side-effects, depending on what else handles this message.
- change LM paypal to use user_load/user_save to manipulate roles (still need to fake an $edit, but code-path is more traditional).
- hack LM paypal to call user_badges method directly, so there are no unexpected side effects etc.
Comment #2
lyricnz commentedOr you could manually recalculate all the badges every so often, like the D6 version does with the function at the bottom of
http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/user_badges...
Comment #3
AppleBag commentedThanks Lyricnz,
I opted for the cron run option, and so far it sems to be working. I signed up to a premium account w/LM Paypal, checked my badges and there was no premium member badge, manually ran cron, looked again at the badges and it was there. For anyone else coming across this post with the same problem, you can just paste this at the bottom of your user_badges.module:
/**
* Implementation of hook_cron()
* - do not forget to set up your cron
*/
function user_badges_cron() {
$result = db_query('SELECT * FROM {user_badges_roles}');
$roles = array();
while ($o = db_fetch_object($result)) {
$roles[$o->rid] = $o->bid;
}
user_badges_save_roles($roles);
}
It'd be nicer obviously to have the badge added instantly, but at least it shows up within an hour, since I have my cron set to run once an hour. =)
Comment #4
lyricnz commentedLM Paypal 6.x-2.0 will likely have better integration support (rules and actions, better use of hooks, etc); so this thing might be easier there. Marking as "won't fix" for now.