Hi,

I'm working on a little module which opens a forum topic for each story you create. The story shows a link to the forum topic in place of the comments system and the forum topic shows the teaser of the story and a link back to this story.

The idea is to bring integration between articles and forums and having a specific forum which contains all the news discussion.

I'm trying to use Drupal's nodeapi so as to make this compatible with any type of node and the node_save() function so as to avoid having to deal with lower-level database calls.

Here is the main problem I encountered during the development of this module. Any help would be welcome. I'm also suggsting some changes in nodeapi in case what I want to do isn't possible using this hook.

I first tried with the submit operation of nodeapi and everything worked fine with the creation of the forum topic but I discovered that submit is also called when I modify a node so I tried with insert. Resulting in forum topics duplicating on each node modification.

The insert operation of nodeapi looks more appropriate for what I want to do. The problem is that insert appears to be called by node_save(). As a result, when I use the node_save() function to save my forum topic, I have an endless loop (the node_save calls nodapi insert operation and the insert operation calls node_save).

Is there a way to save a node without calling the insert operation? Or is there a way, when using the submit operation, to test if the node is created or if it's modified?

Suggestion for nodeapi:
Would Drupal's nodeapi need a new slightly different save_node function that doesn't call insert? Or better a second insert operation that isn't called by node_save, behaving almost the same way as submit does.

Thanks for your help.

Comments

RobRoy’s picture

Test if $node->nid > 0 in 'submit' me thinks.

neural’s picture

Tryed this way, where $node is my story posting and $node2 is the forum topic I create for it.

if ($node->vid == 0){
node_save($node2);
}

Not exactly as you suggested but it looks like it works now!

I'll test it a bit and if everything is ok I close the issue.

Thx for hinting me at this!

ricabrantes’s picture

Status: Active » Closed (fixed)

Closed issue, no activity