I am posting data to a custom View from my (Lotus Approach) database to my website using the services/xmlrpc interface.
I am hand coding everything in in my database in Basic.
I have successfully created a set of nodes from my database.
{user.login; node.save; user.logout with APIkey requires but not session id}
I now need to update a node.
To update a node I understand that I need to add to the node struct
the nid field and changed field thus.

<param>
    <value><struct> <member><name>nid</name><value>413</value></member>
   <member><name>changed</name><value>1215422409</value></member>
.... etc 

However, When I try to update an existing node, the Node.save method returns the OLD node
and in the Drupal Log I get this message:

Duplicate entry '0' for key 1 query: INSERT INTO Ucontent_type_localchurch (field_postcode_value, vid, nid) VALUES ('QQ9 8JJ', 0, 413) in /var/www/html/sites/urc5.org.uk/www/includes/database.mysql.inc on line 172.

Can anyone please advise?

CommentFileSizeAuthor
#9 node_service.module.patch807 byteshurleyit

Comments

DJL’s picture

I am still struggling to get a node to update.

I have located ONE error in my previous approach
my information above :-

To update a node I understand that I need to add to the node struct
the nid field and changed field thus.

was obtained from the node.save service page (admin/build/services/browse/node.save) generated by the services module.
which says

Upon update, node object must include "nid" and "changed".

IT IS INCORRECT
Looking at the module code I see that It should read

Upon update, node object must include "nid" and "revision"

I now get no SQL error (as the module does not attempt an INSERT.)
HOWEVER, the node.save updated still fails with

This content has been modified by another user, changes cannot be saved.

(Both in the DEV build and the official release)

Here is my updating XMLRPC

<?xml version="1.0"?>
<methodCall>
  <methodName>node.save</methodName>
<params>
     <param>
        <value>acd96de4c780364ce194698cecab2d7e</value>
        </param>	
  <param>
    <value><struct> <member><name>nid</name><value>260</value></member>
<member><name>revision</name><value><int>1</int></value></member>
<member><name>type</name><value>localchurch</value></member>
<member><name>name</name><value>ichthus</value></member>
<member><name>uid</name><value>1</value></member>
<member><name>title</name><value>Trinity</value></member>
<member><name>field_church_no</name><value><array><data><value><struct><member><name>value</name><value><string>5A05</string></value></member></struct></value></data></array></value></member>
<member><name>field_servicetimes</name><value><array><data><value><struct><member><name>value</name><value><string>10.45am/6pm</string></value></member></struct></value></data></array></value></member>
<member><name>field_street</name><value><array><data><value><struct><member><name>value</name><value><string>George Street</string></value></member></struct></value></data></array></value></member>
<member><name>field_town</name><value><array><data><value><struct><member><name>value</name><value><string>Burton on Trent</string></value></member></struct></value></data></array></value></member>
<member><name>field_county</name><value><array><data><value><struct><member><name>value</name><value><string>Staffordshire</string></value></member></struct></value></data></array></value></member>
<member><name>field_postcode</name><value><array><data><value><struct><member><name>value</name><value><string>DE14 1DP</string></value></member></struct></value></data></array></value></member>
<member><name>field_website</name><value><array><data><value><struct><member><name>value</name><value><string></string></value></member></struct></value></data></array></value></member>
<member><name>field_email</name><value><array><data><value><struct><member><name>value</name><value><string></string></value></member></struct></value></data></array></value></member>
<member><name>field_secretary</name><value><array><data><value><struct><member><name>value</name><value><string>Revd Peter Howard</string></value></member></struct></value></data></array></value></member>
<member><name>field_sectel</name><value><array><data><value><struct><member><name>value</name><value><string>01283 564439</string></value></member></struct></value></data></array></value></member>
<member><name>field_minister</name><value><array><data><value><struct><member><name>value</name><value><string>Revd Peter Howard</string></value></member></struct></value></data></array></value></member>
<member><name>field_mintel</name><value><array><data><value><struct><member><name>value</name><value><string>01283 564439</string></value></member></struct></value></data></array></value></member>
 </struct></value>
  </param>   
</params> 

CAN anyone HELP?
CAN anyone at least point me toward some decent documentation?

DJL’s picture

Title: Unable to update existing node using node.save via xmprpc » Unable to update existing node using node.save via xmlrpc

I know it is summer (at least in the Northern Hemisphere)
but has anyone any clues on this one?

Thanks in advance

DJL’s picture

Wondering if things were better in the DEV version, downloaded & installed that.
Looking at the code, in this version all that is needed to initiate an UPDATE rather than a save is to include the NID field
The line (in my code above)
<member><name>revision</name><value><int>1</int></value></member>
is in fact superfluous.
In node_service.module, the line

          '#description'  => t('A node object. Upon creation, node object must include "type". Upon update, node object must include "nid" and "changed".'))),

should be replaced with

          '#description'  => t('A node object. Upon creation, node object must include "type". Upon update, node object must include "nid".'))),
DJL’s picture

Having got this far, I wondered if Drupal was remembering the user correctly between XMLRPC calls.
I created a new system method:
The hook:

    // system.me   * Who is the logged in user?  DJL 2008-08-12
    array(
      '#method'   => 'system.me',
      '#callback' => 'system_service_me',
      '#auth'     => false,
      '#return'   => 'struct',
      '#help'     => t('Returns an object containing a logged in user.')
    ),

The implementation

function system_service_me() {
  global $user;
  return $user;
  }

I then executed :
sessid = system.connect
User.login (sessid, key, username, password)
system.me (sessid, key)
user.logout (sessid,key)

system.me returned the correct user!
So why does node.save say that my node has been modified by another user?
Puzzled.

tomhung’s picture

Is there any resolution to this?

I am having the same problem.

Greg

DJL’s picture

EURIKA!!!

I think I have cracked it!!!

I looked at api.drupal.org at the drupal_execute module documentation
and made a guess at changing the code in "function node_service_save"
in the file "node_service.module"
in ... \services\services\node_service folder.

It seems to work!

Here is the full code of 'my' function - I am not into patches!
It

function node_service_save($edit) {
  if ($edit['nid']) {
    $node = node_load($edit['nid']);
    if ($node->nid) {
//
// DJL - from the example in http://api.drupal.org/api/function/drupal_execute/5
// I guess this
// -      $ret = drupal_execute($node->type .'_node_form', $edit, $edit);
      $ret = drupal_execute($node->type .'_node_form', $edit, $node);
//
// DJL patch END
//
    }
  }
  else {
    $ret= drupal_execute($edit['type'] .'_node_form', $edit, $edit);
//PATCH  from  drupal.org/node/139131 (may be updated)
    $path = explode('/', $ret);
    if ($path[0] == 'node' && is_numeric($path[1])) {
      $node = node_load($path[1]);
    }
//END PATCH
    }
  if ($errors = form_get_errors()) {
    return services_error(implode("\n", $errors));
  }
  watchdog('content', t('@type: updated %title.', array('@type' => t($node->type), '%title' => $node->title)), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid));
  return $node;
}
DJL’s picture

Status: Active » Needs review

This does seem to work.
So I have posted this comment to change the Status.....
patch (code needs review)
Does it work for other people?

marcingy’s picture

Status: Needs review » Needs work

please provide a patch in the corrrect format.

hurleyit’s picture

StatusFileSize
new807 bytes

I have a patch that should work but it also removes the unneeded updated watchdog call. Let me know if I need to submit a new version.

marcingy’s picture

Status: Needs work » Fixed

Applied only affects d5.

marcingy’s picture

Status: Fixed » Closed (fixed)