I'm trying to write a module that responds to changes in a user's role. I'm trying to do this in an implementation of hook_user(). I want to be able to quickly change the roles of the users using the table created by the userplus module. However, when I change roles using userplus, the hook_user function is never called. Shouldn't the userplus_admin_userperms_submit() function in userplus.module call module_invoke_all() after it writes the changes to the user roles to the database?

Is there some other way to do this that I'm missing?

Thanks
AC

CommentFileSizeAuthor
#3 userplus_edit_roles_0.patch1.91 KBaclight

Comments

marcp’s picture

I agree -- in this case, userplus should call user_save() for any users whose roles have changed -- user_save() calls module_invoke_all(), so I think that would be the safest thing to do.

If anyone has time to cut a patch for this, please do so. In userplus_admin_userperms_submit(), you'll need to:

1. Figure out which users have had their roles change
2. For each user that has had a role change, load the user, set the new roles, and call user_save()

Shouldn't be too hard...

aclight’s picture

Wouldn't it also make more sense to do the actual changing of the roles via user_save, instead of directly writing to the database?

AC

aclight’s picture

Assigned: Unassigned » aclight
Status: Active » Needs review
StatusFileSize
new1.91 KB

Here's a patch that processes changes in user roles by calling user_save instead of directly writing to the database. It seems to work well for me, with the exception that it seems like it takes a while for the page to reload after I submit the page when I have 25 users/page listed. However, the devel module has short query processing and page processing times, so it could be my server or something.

aclight’s picture

Title: userplus_admin_userperms_submit() should call module_invoke_all » userplus_admin_userperms_submit() should use user_save()
marcp’s picture

Thank you for the patch! I am a bit slammed right now but will test this out soon. Moshe reported a different "feature" of userplus here http://drupal.org/node/88520 that might be right up your alley too. I've just been too busy to get to it.

aclight’s picture

Unfortunately I'm not using og on my site (and in fact I'm using nodeaccess, which I believe is incompatible with og), so I would have no easy way to test any patches relating to userplus and og.

Sorry
AC

marcp’s picture

Version: master » 5.x-1.x-dev
Status: Needs review » Fixed

A modified version of this patch has been applied to the new 5.x release of Userplus. Please test it out!

Anonymous’s picture

Status: Fixed » Closed (fixed)