programmatically UPDATE a node won't work: bug or feature?
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.
On 07 Sep 2006, at 11:10 AM, Augustin (Beginner) wrote:
Also, what would be the difference of using FAPI2 to programmatically update a node, compared to using node_load/edit/node_save?
the node is actually validated. and you know for a fact it's a real working node. also has friendlier concise error messages. otherwise it hits all the same back end stuff. It just happens to be a consistent interface to it (along with all node forms) BTW: if a form is not programmatically submittable, it should be consired a bug, please make an issue for it. there are a handful of forms like this at the moment, but i wasn't aware that node form was one of them. (it was working in my tests here : drupal.org/node/79900)
On Thursday 07 September 2006 07:43 pm, adrian rossouw wrote:
BTW: if a form is not programmatically submittable, it should be consired a bug, please make an issue for it.
there are a handful of forms like this at the moment, but i wasn't aware that node form was one of them.
I submitted the following one, then: programmatically creating a new node type http://drupal.org/node/82908 thanks, augustin. -- http://www.wechange.org/ Because we and the world need to change. http://www.reuniting.info/ Intimate Relationships, peace and harmony in the couple.
Oh, ugh. Nevermind, I just re-read your message and realized I'd completely misunderstood it. Chalk that up to haven't-had-my-coffee-yet. You're correct, the form needs fixing. --Jeff
On Thursday 07 September 2006 10:07 pm, Augustin (Beginner) wrote:
On Thursday 07 September 2006 07:43 pm, adrian rossouw wrote:
BTW: if a form is not programmatically submittable, it should be consired a bug, please make an issue for it.
there are a handful of forms like this at the moment, but i wasn't aware that node form was one of them.
I submitted the following one, then:
programmatically creating a new node type http://drupal.org/node/82908
Another very puzzling one: http://drupal.org/node/83057 programmatically creating forum: parent setting bug A. -- http://www.wechange.org/ Because we and the world need to change. http://www.reuniting.info/ Intimate Relationships, peace and harmony in the couple.
Augustin, That's a good catch. $_POST is indeed not set when programmatically submitting. and from the looks of it, node_validate() is just plain broken for this case. This is one of the things that was fixed by Moshe's patch to the submission/nodeapi/etc handlers. It's understood why it was rolled back before the code freeze, but this will take some puzzling over to fix without breaking other stuff. Is there an issue logged for it? --Jeff Augustin (Beginner) wrote:
Hello again,
$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.
On Thursday 07 September 2006 08:13 pm, Jeff Eaton wrote:
That's a good catch. $_POST is indeed not set when programmatically submitting. and from the looks of it, node_validate() is just plain broken for this case.
This is one of the things that was fixed by Moshe's patch to the submission/nodeapi/etc handlers. It's understood why it was rolled back before the code freeze, but this will take some puzzling over to fix without breaking other stuff.
oh, ok!
Is there an issue logged for it?
There was not because I was not sure it was a bug. Now that you confirm it is, here is the issue: http://drupal.org/node/82905 I hope you'll excuse me if I don't propose a fix: this is currently well above my level of understanding. But if a fix does come, I'll review it. Is my "programmatically creating a node type." problem, I posted earlier on the list another such bug? thanks, Augustin. -- http://www.wechange.org/ Because we and the world need to change. http://www.reuniting.info/ Intimate Relationships, peace and harmony in the couple.
Augustin (Beginner) wrote:
Is my "programmatically creating a node type." problem, I posted earlier on the list another such bug?
thanks,
Augustin.
Nope. One of the reasons that you're facing problems with node creation is that it's a bit more complicated than some other form operations. We're still trying to come up with ways to simplify it, but for the moment what you have to do is: 1) create an array containing the node-type of the node you want to create. array('type'=>'story'), for example. 2) create the values array containing the title, body, name of the author, and so on. 3) use $node->type . '_node_form' as the id of the form you want to create. 4) call drupal execute, passing in the form id, the form values, AND the node. so, the code would look like: $node = array('type' => 'story'); $values['title'] = 'My node title'; $values['body'] = 'My node body'; drupal_execute('story_node_form', $values, $node); --Jeff
On Thursday 07 September 2006 10:03 pm, Jeff Eaton wrote:
Augustin (Beginner) wrote:
Is my "programmatically creating a node type." problem, I posted earlier on the list another such bug?
Nope. One of the reasons that you're facing problems with node creation is that it's a bit more complicated than some other form operations. We're still trying to come up with ways to simplify it, but for the moment what you have to do is:
We are no longer speaking about the same thing. I already have been able to programmatically create a node (but I had problems UPDATing it). I was talking about creating a node TYPE (not a node of a certain type). I have now filed a report about it: http://drupal.org/node/82908 thanks for your help, Augustin. -- http://www.wechange.org/ Because we and the world need to change. http://www.reuniting.info/ Intimate Relationships, peace and harmony in the couple.
On 07 Sep 2006, at 4:42 PM, Augustin (Beginner) wrote:
I was talking about creating a node TYPE (not a node of a certain type). I have now filed a report about it: http://drupal.org/node/82908
yeah. that was one of the issues i had with automating it. once that is sorted though, it will be the best way for install profiles to ship node types. I will be building the macro recorder / player, into an install profile building install profile. =)
On Thursday 07 September 2006 11:01 pm, adrian rossouw wrote:
once that is sorted though, it will be the best way for install profiles to ship node types.
that's precisely what I was trying to do :) A. -- http://www.wechange.org/ Because we and the world need to change. http://www.reuniting.info/ Intimate Relationships, peace and harmony in the couple.
participants (3)
-
adrian rossouw -
Augustin (Beginner) -
Jeff Eaton