Flex and uid

snelson - January 20, 2007 - 21:28
Project:AMFPHP
Version:HEAD
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:active
Description

I wanted to bring up a particularly frustrating problem when using this module with Flex. Flex takes over 'uid' on any object and fills it with its own unique identifier value for the object. This means if a user object is returned, accessing 'uid' of the user in Flex will not actually return the $user->uid, but the Flex unique object key.

As a temporary fix, I am converting any 'uid' to 'userid' using the function below.

<?php
function amfphp_fix_uid($data, $direction = 1) {
 
$uid    = 's:3:"uid";';
 
$userid = 's:6:"userid";';
 
 
$from = ($direction) ? $uid : $userid;
 
$to   = (!$direction) ? $uid : $userid;
 
 
$data = serialize($data);
 
$data = str_replace($from, $to, $data);
 
$data = unserialize($data);
 
  return
$data;
}
?>

I'd like to find a better solution to this problem, so ideas appreciated.

Thanks,
Scott

#1

dineshcooper - April 8, 2008 - 13:49

Came across exactly the same issue,
my workaround adds

$node->userid = $node->uid;

to the function

services_node_load($node, $fields = array())

in the services.module file

#2

snelson - April 11, 2008 - 23:30

The function I posted above is already in AMFPHP core. Your code will only solve the problem in 1 place, when it can be in many, such as user service. Too, this problem only applies to Flash and Flex apps, so it shouldn't affect everybody.

The code in AMFPHP serializes the data, then looks for any "uid" replacing it with "userid". This should take care of any kind of data passed back into Flash or Flex from any service callback. I just think there's got to be a better way than the way I've done it.

If you're not getting a "userid" back from amfphp without your patch, please let me know so I can fix it.

Thanks,
Scott

#3

leoman_730 - August 6, 2008 - 13:39

It looks like the service module or AMFPHP module has problem to save author information when creating a new node. Here is my code:

public function createNode(): void
{
var edit:Object;
edit = new Object;
edit.field_sub_title = new Array({value: sub_title_create.text});
//edit.field_story_type = new Array({value:"1"});
edit.title = title_create.text;
edit.body = body_create.text;
edit.field_story_type = new Array({value: story_type_new.selectedValue.toString()});
edit.field_year = new Array({value: year_new.selectedItem.toString()});
edit.type = 'story';
edit.status = 1;
var formated_where:Array = new Array();
var index:int = 0;
for each (var val:String in where_new.selectedItems) {
formated_where.push({value:val});
}

edit.userid =2;
node.save(edit);
}

Every field works fine; however, the new node always not saving the author information. Thus for every node i created using this function create a node with anonymous author.
And idea on this? Many thanks.

#4

chris_car - August 11, 2008 - 18:02

I think the problem is that you use "edit.userid = 2" instead of "edit.uid = 2"

#5

leoman_730 - August 11, 2008 - 19:03

Chris,

I tried that as well, but that didn't work.
I end up to modify the node_service module to get the author work correctly. Here is a what i have added to the service module:

function node_service_save($edit) {
if ($edit['nid']) {
$node = node_load($edit['nid']);
if ($node->nid) {
$ret = drupal_execute($node->type .'_node_form', $edit, $edit);
}
}
else {
$ret= drupal_execute($edit['type'] .'_node_form', $edit, $edit);

/*****APPLY PATH TO SAVE CORRECT USER INFO*******/
global $user;
$nid = db_result(db_query('SELECT max(nid) FROM {node} WHERE type = "%s"', $edit['type']));
db_query('UPDATE {node} SET uid = %d WHERE nid = %d', $user->uid, $nid);
/******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;
}

#6

snelson - February 15, 2009 - 01:39

You needed to include the user name in the node.save operation. Without the name, drupal will not save the correct author. Add node.name = "username" and you should be good to go.

Scott

#7

snelson - February 15, 2009 - 01:42

I have modified the serialize function call to be more memory efficient based on #344476: Trouble with serialize call in amfphp module using ridiculous amounts of memory., but I still don't like this. Any thoughts, solutions / suggestions would be great.

- Scott

#8

2pha - March 20, 2009 - 05:46

Today when calling system.connect from flash, sometimes it was returning false, dunno why.
Tracked it down to:
$data = unserialize($data);
in the fix_uid function.

As Im using flash and only wanting the sessionId, I could skip the fix_uid function no worries.

There's some sort of issue there, thats all I'm sayin'

 
 

Drupal is a registered trademark of Dries Buytaert.