Problem with showing new badges for users promoted to new roles by userpoint module
| Project: | User Points Contributed modules |
| Version: | 5.x-3.x-dev |
| Component: | Code: userpoints_role |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
I have just created a bug report with user_badge module (In http://drupal.org/node/161822 ) with the following description:
Userpoints module has been integrated with user_badges module and can automatically promote users to new roles upon their gaining certain thresholds set in userpoints' settings. This tandem of two modules would be just perfect if not a problem with showing new badges for the users promoted to new roles. It does not show until you go to such a user's account page 1) uncheck new role (demote user from a new role), 2) save, 3) go into account editing page again and manually check new role again and save. I guess saving the user's account trigers something, some kind of record to database, which was missed by userpoints' module when it was promoting the user to a new role. I am not sure which exact module between the two this problem belongs to. So I am creating this issue for both modules.
I tend to think this is more of user_badge module's problem. Nevertheless, I think that userpoints_role module could really take care for solving this issue, since it is responsible for saving settings in database for a promoted user's new role. I believe the issue would be solved if userpoints_role would follow the following logic when saving new settings for the user:
1) to check if user_badges module is installed;
2) if it is not, then go usual way and save new settings for the user just for userpoints_role part. or else
3) if it is, then to save changes for the user_badges database tables too.

#1
Could User Point Module Maintainers invoke user_hooks, so that other modules can respond to the role change, as was suggested by Heine here: http://drupal.org/node/161822
#2
#3
I have the same problem, and here's what I found:
userpoints_role used to call user_multiple_role_edit() in the function _userpoints_role_join(). user_multiple_role_edit() calls user_save() to update the user. UserBadges implements hook_user, which updates the user/badge association on the update operation.
The latest version of userpoints_role does not do this. It directly inserts data into the database instead of calling the user_multiple_role_edit() function.
User_badges is working just fine as is - the problem lies with the userpoints_role module.
We need to patch userpoints_role one way or the other; either insert directly into the database to udpate the badge, or implement hook_user.
#4
The fix is really quite simple - see attached patch.
#5
I should note that my patch is applied to version 5.x-3.3 of userpoints - there was an exact same patch applied to the 5.x-2.9 version of userpoints_role that was somehow left out of the latest 5.3 branch.
#6
Fixed in 3.x-dev.
Thank you.
#7
Automatically closed -- issue fixed for two weeks with no activity.