Posted by jussi on March 22, 2010 at 10:04am
Hello all!
Looks like this is a heck of module, I must say. I'm wondering what might be your take on this problem I'm facing: on the site, there's a custom content type "Document" which can have "related" forum topics for commenting (created with the help of Discuss This! -module). I'm looking at a case where a forum topic has been created for some Document but this Document is going to be deleted. Now there's forum topic pointing to a non-existing Document-node, not good.
So, where to go from here? Custom rule altogether? Or might some PHP be enough here? The forum topic and Document share the same "title", could it be used to identify what to delete?
Cheers.
Comments
Some thoughts
If you're using node reference to refer from the forum to the document, I think the reference will be deleted automatically when the document disappears. (Actions like these explain why it is much quicker to create 20 nodes programatically than to delete them afterwards.)
But you would want to delete the forum anyway, since it doesn't fill any purpose any more. :-)
Here are two ideas on how to do it:
-1-
Use a trigger on node deletion, and call an action that finds and deletes the relevant forum. If you have a reference from document to forum this will be pretty easy – just run the "load node" action and use the node reference to load the forum. If you have a reference from forum to document you'll have a more tricky situation, and you'll have to do some querying to find the forum to delete. My way of doing this is to call Views Bulk Operations from Rules.
-2-
If you don't mind having orphaned forums lying around a short while you could consider having a clean-up session every night or so, that find the orphaned forums and deletes them. Again, this can be done with VBO, and you'd execute the VBO programatically either on midnight cron runs, or have it called by Rules Scheduler periodically.
The only reason to choose the second approach is if you want to have quick deletions of documents, for example if you exect that clients will be deleting multiple documents at once (and don't want every deletion to take some extra time). Otherwise the first approach is probably more efficient, and definately more direct.
Good luck!
//Johan Falk, NodeOne, Sweden