Closed (won't fix)
Project:
Services
Version:
5.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
18 Feb 2009 at 03:38 UTC
Updated:
10 Mar 2009 at 01:58 UTC
I had a look in CVS and it appears as though some work has gone into node_service_save which is great. However, I think it should return the saved node object instead of nid as some extra information is added to the node object on save (eg. vid, created, changed) that the invoker of the service might want to know about. The description of the service in node_service_service says it will return a node object anyway.
The last line of the function could just be changed to:
return node_load($nid);
Comments
Comment #1
dazweeja commentedI've also found that the current version of node.save doesn't trigger hook_nodeapi hooks (I think this is very important) so I've changed mine to:
function node_service_save($edit, $fields = array()) {
$val = new StdClass();
foreach ($edit as $key => $value) {
$val->{$key} = $value;
}
node_save($val);
return services_node_load($val, $fields);
}
Note the fields array because I'm returning a node object as above.
Comment #2
marcingy commenteddruapl_excute simulates the submission of node form and as a result hook_nodeapi is called. Also in addition if node retrival is required, called node.save followed by node.get, as in all cases the user does not always need/won't the full node returned on a save.
Comment #3
dazweeja commentedOK, thanks for looking into this. drupal_execute wasn't calling the hooks for me but it might have had something to do with my particular setup. As for returning the nid vs returning the node, I guess it's a design decision about how often developers want to get back all the extra information that is added to the node object on save. I do it often so I'd definitely prefer to avoid the lag of an extra trip to the server. If it's reasonably common for other developers too, it would only take an extra line of code to account for both cases. For example this would do it in a backwards-compatible way with no extra server load for those who just want the nid:
function node_service_save($edit, $fields = NULL) {
...
if($fields) return services_node_load(node_load(array('nid' => $nid)), $fields);
else return $nid;
}