Closed (won't fix)
Project:
Services
Version:
6.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
2 Sep 2009 at 12:03 UTC
Updated:
30 Sep 2009 at 19:57 UTC
Currently, you can't just use node.load, modify data a bit and save it back with node.save.
The culprit is drupal_execute() which is currently used in node_service_save().
How about the following instead of using a pseudo-form and drupal_execute():
$n = node_submit($edit);
node_object_prepare($n);
$form = array();
node_validate($n, $form);
if ($errors = form_get_errors()) {
return webservices_error(implode("\n", $errors));
}
// TODO: check $form for errors and return them if there are
node_save($n);
I'm using this currently to create new nodes with date- and link-fields and it seems to work fine (minus a minor problem with the attributes-property of the cck link field).
If you're interested I can come up with a patch to make node_service_save() use this for create and edit.
Comments
Comment #1
marcingy commenteddrupal_execute needs to be used as it simulates the submission of the form and ensures that all the correct hooks are fired before the node is saved. The issue is likely that your data structure is incorrect that and as a result is not being processed correctly by the cck.
Comment #2
marcingy commentedwrong status
Comment #3
ray007 commentedThe problem with drupal_execute() is, that i.e. cck date-fields have a different format depending on the widget setup. It's completely different than what you get if you load the node. The current way doesn't work if you have cck-fields other than text.
So the question is: what hooks get missed by calling node_submit(), node_object_prepare(), node_validate() and node_save()?
Should be possible to execute those hooks in node_service_save() ...
Comment #4
marcingy commentedIt does work with none text fields - you simply need to be build the correct data structure in the first place. drupal_executes simulates the submission of a drupal node form and hence the key is data structure.
Comment #5
ray007 commentedOk, so simple loading and saving back is not of concern.
Can you then maybe tell me how to do it with a date-field?
Haven't yet managed to save a node with a datefield (or linkfield) ...
Comment #6
DartonW commentedI got CCK date fields to update by sending the XML-RPC as a string:
where $node["expiredate"] is simply a Unix timestamp, e.g. 1254339953.