[development] programmatically UPDATE a node won't work: bug or feature?

Augustin (Beginner) drupal.beginner at wechange.org
Thu Sep 7 09:10:30 UTC 2006


Hello again,


I was trying to update a node using FAPI2, but it completely failed. I wanted 
to try out FAPI2, to see how it worked.

I am now going to use the easier method (as I have been advised earlier) of 
doing:
1) node_load($nid);
2) edit the object
3) node_save($node);


I mention what follows in case it is an actual bug that needs fixing:

First, I found out that I must cast the node into an array:

      $node = (array) node_load($nid);

      $values['title'] = $question['q_desc'];
      $values['body'] = theme('demexp_question_body', $question);
      //  $values['changed'] = time();
      drupal_execute('demexp_question_node_form', $values, $node);

but drupal_execute fails.
I get: "This content has been modified by another user, changes cannot be 
saved." which comes from here:

  if (isset($node->nid) && (node_last_changed($node->nid) > 
$_POST['changed'])) {	
    form_set_error('changed', t('This content has been modified by another 
user, changes cannot be saved.'));
  }

now, with the FAPI push method, $_POST is not set, is it?
so the check above always fail.

Is this another bug?
I've tried setting $values['changed']  but to no avail.

If it's a bug, I can submit a report.


Also, what would be the difference of using FAPI2 to programmatically update a 
node, compared to using node_load/edit/node_save?


Augustin.


p.s., yes, I do review a few bug patches, too, though not as many as others.


-- 
http://www.wechange.org/
Because we and the world need to change.
 
http://www.reuniting.info/
Intimate Relationships, peace and harmony in the couple.


More information about the development mailing list