Problem/Motivation
When MS Membership adds or removes roles, it does it by inserting or removing them directly in the database. This works fine however in my use case it is critical that the event "After updating an existing user account" gets triggered. Because of the way the roles are altered now this thous not happen.
Proposed resolution
In file: ms_membership.module in both function ms_membership_add_role($uid, $rid) and function ms_membership_remove_role($uid, $rid) change
db_insert('users_roles')
->fields(array(
'uid' => $account->uid,
'rid' => $rid,
))
->execute();and
db_delete('users_roles')
->condition('uid', $account->uid)
->condition('rid', $rid)
->execute();to
user_multiple_role_edit(array($uid), 'add_role', $rid); and user_multiple_role_edit(array($uid), 'remove_role', $rid);
respectively.
Now the event "After updating an existing user account" gets triggered properly. I have tested this and it seems to function fine this way. I also believe this is a much "cleaner" way to assign and remove roles from user accounts programmaticely.
If i figure out on how to create patch files i will try to attach it to this issue.
Kind regards,
Tavorick
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 2830583.patch | 1.42 KB | Tavorick |
| #2 | [membership-adding-and-removing-roles-alter]-[2830583]-[1].patch | 1.42 KB | Tavorick |
Comments
Comment #2
Tavorick commentedComment #3
Tavorick commentedComment #5
Tavorick commentedComment #6
Tavorick commentedComment #7
Tavorick commentedI am running this solution for more than a month now on a live website and i have not encountered any problems. This patch can be safely implemented by anyone without problems.
Comment #8
cosolom commentedI also want to mention that the problem is more critical (not only not the fired rule). I used an email verification process that was override membership's roles because the user object in the cache did not have actual roles