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

Comments

tavorick created an issue. See original summary.

Tavorick’s picture

Tavorick’s picture

Status: Active » Needs review

Status: Needs review » Needs work
Tavorick’s picture

StatusFileSize
new1.42 KB
Tavorick’s picture

Status: Needs work » Needs review
Tavorick’s picture

Status: Needs review » Reviewed & tested by the community

I 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.

cosolom’s picture

Priority: Normal » Major

I 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