function services_client_make_user_call in Services Client 7
Make the actual user create/update call for each connection and task
Parameters
object $user: This is the user object which was just saved
object $task: Contains the field mappings and other data
object $conn: This contains the connection data to reach the services server
Return value
boolean TRUE or FALSE for whether or not the request was successful
1 call to services_client_make_user_call()
- services_client_make_call in ./
services_client.module - Make call to remote site by event $type
File
- ./
services_client.module, line 621 - Services client module allows to push different types of objects on different types of events such as node_save, user_save to remote masters.
Code
function services_client_make_user_call($user, $task) {
// Exclude users that shouldn't be synced
if (services_client_user_exclude($user)) {
return TRUE;
}
// Generate our connection object. If false, then we failed login.
$client = services_client_connection_get($task->conn_name);
// Generate the user object
$user_data = new stdClass();
// Load up the mapping
$conds = $task->config['condition']['config'];
$mapping = $task->config['mapping']['config'];
$fields = explode("\n", $mapping['field_mapping']);
$fields_empty = services_client_process_mapping_prepare_empty(isset($mapping['field_mapping_empty']) ? $mapping['field_mapping_empty'] : array());
// Process the field mapping and assign to the data object we are passing to services server
$user_data = services_client_process_mapping($user, $fields, $fields_empty);
// If UUID is available
if (!empty($user->uuid)) {
$user_data->uuid = $user->uuid;
}
if (isset($user->_services_client)) {
$user_data->_services_client = $user->_services_client;
}
// Add roles to user data
services_client_process_roles_mapping($user, $user_data, $mapping['user_sync_roles'], $client, $task->conn_name);
// Because different calls and versions of the services module use both data
// or account depending on various conditions, we apply the data to both.
$data = (array) $user_data;
// TODO DEBUGGING REMOVE ME
watchdog('sc_user', 'Sending user to %conn: <pre>@user</pre>', array(
'%conn' => $task->conn_name,
'@user' => print_r($data, TRUE),
));
// Find out if there is already an object on the master server with this UUID
$remote_name = isset($user->original->name) ? $user->original->name : $user->name;
if (variable_get('services_client_user_sync_byname', TRUE) && $remote_name) {
$result = $client
->index('user', 'uid,name', array(
'name' => $remote_name,
));
if (!empty($result)) {
$uid = $result[0]['uid'];
}
}
else {
$uid = services_client_scalar_result($client
->get('uuid', 'user', array(
'uuid' => $user->uuid,
)));
}
// We have a result. We need to update the node
if (!empty($uid)) {
watchdog('sc_user', 'Got @uid for uuid @uuid', array(
'@uid' => $uid,
'@uuid' => $user->uuid,
));
// Update the user on the services master
$client
->update('user_raw', $uid, $data);
}
else {
// Create the user on the services master
$client
->create('user_raw', $data);
}
}