Hi,

I have a large set of data that I try to make accessible with an drupal installation.
I used the node import module to import two types of content types, where one is the basis and the other one should be attached to these base nodes via node comments. Every node comment content type has a field with the NID of its parent. There are no threads or anything fancy.

Now, how would I go ahead to attach the node comment cts to their appropriate parent? I guess it would be easiest to do this programmatically as I really have a rather big set of data.

Any help would be appreciated.
Andrej

Comments

crea’s picture

Status: Active » Fixed

I can only recommend to look at the nodecomment_save() function which does most of the additional comment-related job.

andrej235’s picture

This seems to be the way to go. However, I can't find out how to use the function on the already existing nodes. More specifically, what is the structure the node argument must have?

andrej235’s picture

So here a short template how to do it. Correct me if it is wrong.
I am not sure what to do with the thread part. Maybe some illumination on it?

$node_type = 'node_type_name';
$result = db_query("SELECT nid FROM {node} WHERE type='%s'",$node_type);
while ($row = db_fetch_object($result)){
$node = node_load($row->nid);
$target = $node->field_nid[0]['value'];
$node->comment_target_nid = $target;
$node->comment_target_cid = 0 ;
nodecomment_save($node);
}

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.