So as per my comments on the group, here is a patch that deletes profiles when a user is deleted.

It does this by default at the moment, but I guess a setting could be added to change this.

Comments

fago’s picture

Status: Needs review » Needs work

I'm OK with this as default action.
But you need to track down the nodefamily relations, e.g. the grandchildren of a nodeprofile should be also deleted.

Further I would like a bit more elegant code (looking at the $query_types..). E.g. you could directly use something like

$node = node_load(array('type' => $type, 'uid' => $uid));
node_delete($node->nid);

in the nodeprofile loop, or use implode() instead.

jpetso’s picture

After some experiments with node_load() and subsequent inspection of the user_confirm_delete_submit() code, it's quite clear that the node_load() approach will not work because the user is deleted from the {user} table before hook_user() is called. And if node_load() doesn't find the user entry in the database then it sets the node's uid to 0, so we can't filter by uid.

Which means that a direct query is the way to go. Soon to come.

jpetso’s picture

Turns out that the uid of the {node} entry is already at 0, no matter if retrieved by node_load() or direct database query. Maybe it depends on the ordering of the modules, or something I currently didn't think of. In any case, I can't get it working here at the moment, at least with 4.7. Let me think about this for a while.

fago’s picture

yes, actually it's a case of module ordering. We could adapt that or we could also get the usernode-id and retrieve the ids of the profiles about the nodefamily relations. But that would require the usernode module for this functionality.

So I think it would be better to order the module appropriate, here is an handbook page about module weighting:
http://drupal.org/node/110238.

jpetso’s picture

Bad news, module ordering doesn't work. module.inc always places the filter, node, system, user, and watchdog modules at the very beginning of the module list, so we can never get called before node.module. Bastards.

jpetso’s picture

Hm... node et al. are always put to the top of the list in Drupal 4.7, but not in Drupal 5! That means it should work there, I'll try it out instantly.

jpetso’s picture

Status: Needs work » Needs review
StatusFileSize
new4.69 KB

Ok, here's the solution, but you won't like it, and neither do I.

The good news is that it works, and that it doesn't require the usernode module to exist. The bad news is that node_load() doesn't work (see the comments in the patch), and because of that, node_delete() also doesn't work. Which means we have to go db_query() all the way.

fago’s picture

Status: Needs review » Needs work

good work!
I think its the best way we can do that.

But I think we should call nodeapi load like node_load() does, so that modules that use nodeapi op delete get their full node object, like they except it.

Then I fink the function _nodeprofile_relation_descendants_dive() should go into the nodefamily module as another API function - that might be useful in other cases too.

jpetso’s picture

Status: Needs work » Needs review
StatusFileSize
new4.99 KB

Include 'load' invokes, and make the patch dependent on issue #121578, getting rid of _nodeprofile_relation_descendants_dive() as private function and taking it from nodefamily instead.

fago’s picture

Status: Needs review » Fixed

works like expected, good work!
committed to 5.x and HEAD.

Anonymous’s picture

Status: Fixed » Closed (fixed)