I deleted a role from admin/user/roles/edit/3 (press delete button), but when I looked at the nodeaccess table I saw that rid=3 was still there. I had to "DELETE from nodeaccess where gid=3" to clean up the table. Its important because a large site will have N*R entries in the nodeaccess table where N="number of nodes" and R="number of roles" and that gets large very quickly.

In the short run - having a hook for the module that deletes roles and having a "DELETE from nodeaccess where gid=..." would
be best. Or "DELETE FROM nodeaccess where gid NOT IN SELECT DISTINCT rid from role" would do the trick too at any stage. (WARNING: SQL is a rough guess - I haven't tested it)

Comments

Anonymous’s picture

Unfortunately, drupal does not provide any mechanism for a module to be notified when a role is deleted, changes names or is created. However, if after deleting a role you resubmit the nodeaccess admin form, it should get rid of all those entries.

kiz_0987’s picture

debtman7 -- actually there is a way for a module to be notified of role changes (we use this in the 5--2 branch of the gallery module). Use hook_form_alter and check the form id -- then add a submit handler. Something like:

function nodeaccess_form_alter($form_id, &$form) {
  if (($form_id == 'user_admin_role') || ($form_id == 'user_admin_new_role')) {
    $form['#submit']['_nodeaccess_role_submit'] = array();
  }
Anonymous’s picture

Yeah I figured someone would point that out. I really don't like the idea of jacking another form... But there's not much other way to do it. I'll look into it once some other things are sorted out.

mantyla’s picture

Status: Active » Closed (fixed)

This will be fixed in the future 2.0 release - but only if the role edit form is used to create/delete roles. If this is done by another module (LDAP Integration for instance adds roles without the role edit form), then there is no way for Nodeaccess to know. As a failsafe, saving the admin settings twice will ensure that Nodeaccess is aware of all roles.