save node in SWX

bassam - July 31, 2008 - 09:54
Project:SWX
Version:5.x-1.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

Hi,

I tried to save a node using SWX but it's not working.
The result shows that the node was saved, but when I check in Drupal it shows that the node is empty (no title, no body, nothing).

Here's the code I wrote.

import org.swxformat.SWX;
var swx:SWX = new SWX();
swx.gateway = "http://localhost/drupal_test/services/swx";
swx.encoding = "GET";
swx.debug = true;

var callParameters:Object = {
serviceClass:"Drupal",
method:"callService",
args:['node.load', [2]],
result:[this, resultHandler],
};

var callParametersSave:Object = {
serviceClass:"Drupal",
method:"callService",
args:['node.save', [_root.node]],
result:[this, saveResultHandler],
fault:[this, saveFaultHandler]
};

swx.call(callParameters);

function resultHandler(event:Object) {
// assign loaded node
_root.node = event.result;

// set args for new save request
callParametersSave.args = ['node.save', [_root.node]];
swx.call(callParametersSave);
}



function saveResultHandler(event:Object) {
trace("===============saved================");
}

function saveFaultHandler(event:Object) {
trace("--------------ERROR--------------");
}

Any help is appreciated.

#1

timosea - September 12, 2008 - 10:35
Component:Miscellaneous» Code

Did you find a solution to this node save issue?

I have a very similar problem and can not work it out either, i thought it was a permissions problem, so created the following script (as2) to test this theory.

My demo user can edit node 111 from drupal, so thought if create a session and log that user in load node 111 then modify the title and save it, it should work, but guess I'm still doing something wrong; the non-existent session fault msg at the end is kind of concerning too!

Help would be most welcome;)

System.security.allowDomain("http://www.mysite.com");
import org.swxformat.SWX;
_root.createTextField ("status",0,0,0,240,320)
//
var swx:SWX = new SWX();
swx.gateway = "http://www.mysite.com/services/swx";
swx.encoding = "GET";
swx.debug = true;
swx.timeout = 10;
var callConnection:Object = {serviceClass:"Drupal", method:"callService", args:['system.connect',['0']], result:[this, connectionHandler], timeout:[this, timeoutHandler], fault:[this, faultHandler]};
swx.call(callConnection);
var sessionid = ""
//
function connectionHandler(event:Object) {
sessionid = event.result.sessid
status.text = "Session ID: "+sessionid
var callLoginScript:Object = {serviceClass:"Drupal", method:"callService", args:['user.login', [sessionid,'demo','demo']], result:[this, loginHandler], timeout:[this, timeoutHandler], fault:[this, faultHandler]};
    swx.call(callLoginScript)
}
var NodeID = 0
function loginHandler(event:Object) {
NodeID = 111 //just a standard story node that the demo user can modify from drupal
status.text += "\r\rUser: "+event.result.user.name+"\rsession id: "+event.result.sessid
var callGetNode:Object = {serviceClass:"Drupal", method:"callService", args:['node.load', [sessionid,NodeID]], result:[this, nodeHandler], timeout:[this, timeoutHandler], fault:[this, faultHandler]};
swx.call(callGetNode);
}
var nodeobj:Object = new Object()
function nodeHandler(event:Object) {
nodeobj = event.result
status.text += "\rnode nid: "+nodeobj.nid
status.text += "\rnode type: "+nodeobj.type
status.text += "\rnode title: "+nodeobj.title
nodeobj.title += " UPDATED BY SWX"
nodeobj.changed++
var callUpdateNode:Object = {serviceClass:"Drupal", method:"callService", args:['node.save', [sessionid, nodeobj]], result:[this, confirmUpdateHandler], timeout:[this, timeoutHandler], fault:[this, faultHandler]};
swx.call(callUpdateNode);
}
function confirmUpdateHandler(event:Object) {
nodeobj= event.result
status.text += "\r\rconfirmUpdateHandler"
status.text +="\rrresult = "+event.result
status.text += "\rUPDATED:\rnode title: "+nodeobj.title
var callLogOut:Object = {serviceClass:"Drupal", method:"callService", args:['user.logout', [sessionid]], result:[this, logOutHandler], timeout:[this, timeoutHandler], fault:[this, faultHandler]};
swx.call(callLogOut);
}
function LogOutHandler(){
status.text += "\r\rLOGGED OUT"
}
function timeoutHandler(event:Object) {
status.text += "Call timed out!";
}
function faultHandler(event:Object) {
status.text += "\r\rError:"+event.fault.message
}
//
/*My demo user can update story nodes via drupal but i still get the following out from flash (as2):
============================
Session ID: b69ffd5d79d92b11abca23a29ee39a72

User: demo
session id: b69ffd5d79d92b11abca23a29ee39a72
node nid: 111
node type: story
node title: Under Construction

confirmUpdateHandler
rresult = Access denied.
UPDATED:
node title: undefined

Error:Error 2: session_encode() [<a href='function.session-encode'>function.session-encode</a>]: Cannot encode non-existent session. in /home/mysite/public_html/modules/_3rdparty/services/services.module, line 615.
===========================
*/

#2

bassam - September 29, 2008 - 10:43

Hi,
Sorry man, no luck.

I ended up creating a new service that takes multiple parameters and then I save the node using node_save().

Please report back if you figured something out.

Best of luck.

#3

timosea - October 28, 2008 - 13:25

Sorry about the delay, in posting back, I'm on drupal stuff on regularly irregular bases.

In the end after trying most of the other services modules I end up using the built in xmlrpc service combined with mattism as2 classes which work seamlessly with flashlite3 until wanted save cck fields; in the end I hacked the mattism classes to allow pre-formatted xml strings through for cck fields.

 
 

Drupal is a registered trademark of Dries Buytaert.