Skip to: Site menu | Main content


Role Playing: Clear the Cache

Maybe this was covered somewhere on awhile back, but either I wasn't searching using the correct terms or I just plain missed it. I'm talking about how to avoid issues when programmatically modifying user roles.

I was working on a module that automatically adds and removes user roles when certain conditions are met. The code to remove and add a user role is pretty straight-forward:

db_query("DELETE FROM {users_roles} WHERE uid = %d AND rid = %d", $user->uid, $rid_to_delete);
db_query("INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)", $user->uid, $rid_to_add);

I thought this was all I needed to do. My initial testing didn't find anything unexpected, so I moved on to something else.

Submitted by michael on Mon, 05/12/2008 - 1:43pm
Filed under: