I suggest adding this to user include. I also suggest renaming install_set_permissions() to install_add_permissions() since thats all it can do due to $perms = array_unique(array_merge($perms, (array)$existing_perms));. That code is useful for set and forget adding of a perm so thats why I propose to keep the function, but change its name.
/**
* Remove permissions for a certain role.
*/
function install_remove_permissions($rid, $perms) {
// Retrieve the currently set permissions.
$result = db_query("SELECT p.perm FROM {role} r INNER JOIN {permission} p ON p.rid = r.rid WHERE r.rid = %d ", $rid);
$existing_perms = array();
while ($row = db_fetch_object($result)) {
$existing_perms += explode(', ', $row->perm);
}
$new_perms = array_diff($existing_perms, $perms);
// Update the permissions.
db_query('DELETE FROM {permission} WHERE rid = %d', $rid);
db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, implode(', ', $new_perms));
}
Comments
Comment #1
moshe weitzman commentedCommitted, with name change to install_add_permissions. Existing code will need updating.