I am using the following function in a custom module, in a hook_nodeapi:

foreach ($node->field_daily_report_equipment_use as $key => $item) {
$equipnode = node_load($item['nid']);
if(certain conditions) {
$comment = '';
$equipmentnode = '';
$comment['comment'] = 'Usage is now' . $node->field_daily_report_equip_usage[$key]['value'];
$comment['uid'] = $node->uid;
$comment['nid'] = $node->field_daily_report_equipment_use[$key]['nid'];
$equipmentnode['field_equipmentlastusagecount'][0]['value'] = $node->field_daily_report_equip_usage[$key]['value'];
$equipmentnode['field_equipmentlastusagerecorded'][0]['value']['date'] = date('n/j/Y', strtotime($node->field_daily_report_date[0]['value']));
$equipmentnode['field_equipmentlastsrvtime'][0]['value']['date'] = date('n/j/Y', strtotime($equipnode->field_equipmentlastsrvtime[0]['value']));
comment_driven_save($equipmentnode, $comment, $errors);
}
}

For the first run through the foreach (or if there is only one row in the array) the comment_driven_save works perfectly. However, on subsequent runs, the submitted comment is malformed, with the comment "2", submittted by "Anonymous", and comment_driven properties not being applied to the node (in fact, no new node revision is created).

I've dumped the $comment and $equipmentnode variables prior to comment_driven_save on all runs, and the data is good (correct comment, uid, nid, and driven properties).

Any ideas? Is there something obviously wrong in my code (certainly a possibility)?

Comments

obrienmd’s picture

Also of note - Because the comment is Anonymous, it is queued for approval rather than published immediately... Not that this really matters in this case.

arhak’s picture

obrienmd’s picture

Yikes, this seems quite complicated! Will try to debug more ASAP, but not sure I yet have the technical ability to provide much help...

obrienmd’s picture

Someone on IRC mentioned clearning the static cache by initializing $_POST before each run of the loop (and saving the $_POST before the loop executes / restoring it after the loop executes). I tried this, but ended up with the same result.

obrienmd’s picture

Arhak, and recommendations? I would think that my effort in #4 would have invalidated #260934 (as $_POST holds the cache)... I'll have to do more digging on #766146.

arhak’s picture

Status: Active » Postponed

I think cdriven can't be pushed much farther without a rewrite to change sensitive pieces of code.
It is time to get more hands on it, a few interested developer and several even more interested users to test and report useful feedback for a lot of configurations, to check whether they hold or not (since writing actual tests would be a titanic goal)