function services_client_make_submission_to_node_call in Services Client 7
Make the actual node create/update call for each connection and task
Parameters
object $node: This is the node object which was just saved.
object $task: Contains the field mappings and other data
Return value
boolean TRUE or FALSE for whether or not the request was successful
1 call to services_client_make_submission_to_node_call()
- services_client_make_call in ./
services_client.module - Make call to remote site by event $type
File
- ./
services_client.module, line 810 - 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_submission_to_node_call($submission, $task) {
// Generate our connection object. If false, then we failed login.
$client = services_client_connection_get($task->conn_name);
// Lets load up that mapping and do our thing
$conds = $task->config['condition']['config'];
$mapping = $task->config['mapping']['config'];
$fields = explode("\n", $mapping['field_mapping']);
$types = explode("\n", $mapping['node_type_mapping']);
$fields_empty = services_client_process_mapping_prepare_empty(isset($mapping['field_mapping_empty']) ? $mapping['field_mapping_empty'] : '');
//Get the field name on master nodes - what field to update with attached files
$file_field_name = $mapping['file_field_name'];
// Process the field mapping and assign to the data object we are passing to services server
$submission_data = services_client_process_mapping($submission, $fields, $fields_empty);
// Override field mapping of types to allow substitution/transformation
if (count($types) > 0) {
$submission_data->type = services_client_type_override($types, 'webform');
}
// set revision and language, just in case.
$submission_data->revision = '';
$submission_data->language = LANGUAGE_NONE;
if (isset($submission->_services_client)) {
$submission_data->_services_client = $submission->_services_client;
}
// Node data needs to be an array containing an object.
$data = (array) $submission_data;
// TODO DEBUGGING REMOVE ME
watchdog('sc_node', 'Sending node to %conn: <pre>@node</pre>', array(
'%conn' => $task->conn_name,
'@node' => print_r($data, TRUE),
));
// Create the node on the services master
$response = $client
->create('node_raw', $data);
$response_nid = $response['nid'];
// Check if there some files to be uploaded
if (count($submission->file_usage['added_fids'])) {
// Hardcoded for now
$file = file_load($submission->file_usage['added_fids'][0]);
$file_data = array(
'file' => base64_encode(file_get_contents($file->uri)),
'filename' => $file->filename,
);
// Send file to remote endpoint and get fid
$response = $client
->create('file', $file_data);
// Attach new created file to node
$data = array(
'field_name' => $file_field_name,
'fid' => $response['fid'],
);
$client
->targetAction('node_raw', $response_nid, 'attach_file', $data);
}
}