Not sure if this is a bug on nodefamily or on usernode???

but.. shouldn't deleting a user delete the nodes "attached" to the usernode?

when i delete a user now the usernode gets deleted and the attached nodes remain but are now shown as being owned by anon (since their original owner was just deleted).

i can likely do an external hook_user on delete to clean things up; but not sure why your modules don't do it automatically - is there a reason that perhaps these nodes might want to be left in the system for some applications??

Comments

jpetso’s picture

No, this is not intended, those nodes should have been deleted.

fago’s picture

Project: Node Family » Node Profile

this is only implemented for 5.x, in 4.7.x this won't be fixed as it isn't that easy one thinks... Have a look at this nodeprofile issue: http://drupal.org/node/90838

However it's easier if one relies on the usernode module, of course a patch would be welcome!

aclight’s picture

Here is some code I use on my site to do this. This is part of a separate module I have worked on.

/*
 * Implementation of hook_user
 */
function autoprofiles_user($op, &$edit, &$user, $category = NULL) {
  switch ($op) {
    case 'insert':
    case 'login':
       // .......
      break;
    
    case 'update':
       // .......
      break;
      
    case 'delete':
      // delete all children nodes of the user's usernode (eg. nodeprofiles)
      if (function_exists('usernode_get_node_id')) {
        $nid = usernode_get_node_id($user);   // get this user's usernode nid
      }

      if (function_exists('nodefamily_relation_load_by_type')) {
        if ($nid) {
          $children_nodes = nodefamily_relation_load($nid, 0);    // load all child nodes (only 1 level of child nodes)
          foreach ($children_nodes as $child_node) {
            node_delete($child_node->nid);
          }
        }
      }

      break;
  }
}
<

Note the following:

  1. I'm using a version of nodefamily for 4.7 but it's a rather old version (probably from around December of 2006). The API may have changed sufficiently since then that this code no longer works.
  2. This will only delete immediate children nodes of the usernode. It doesn't dig down to the grandchild level, etc.
  3. I haven't thoroughly tested this code, so I can't promise it will work as intended or at all. Make sure to keep backups.

Good luck
AC

fago’s picture

if one comes up with a usernode dependent patch for nodeprofile 4.7.x, which also deletes all grandchildren properly, I'd happily commit it. But don't forget to respect module_exist('usernode')..

I won't write that, as I'm concentrating on 5.x now..