saving nodes with non-text cck-fields
ray007 - September 2, 2009 - 12:03
| Project: | Services |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | won't fix |
Jump to:
Description
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():
<?php
$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.

#1
drupal_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.
#2
wrong status
#3
The 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() ...
#4
It 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.
#5
Ok, 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) ...
#6
I got CCK date fields to update by sending the XML-RPC as a string:
"field_expiredate" => new xmlrpcval(array(new xmlrpcval(array("value" => new xmlrpcval($node["expiredate"])), "struct")), "array")where $node["expiredate"] is simply a Unix timestamp, e.g. 1254339953.