You are here

function sf_notifications_update_record in Salesforce Suite 7.2

Same name and namespace in other branches
  1. 6.2 sf_notifications/sf_notifications.module \sf_notifications_update_record()

Helper function for _sf_notifications_handle_message() - attempt to update (or insert if $object_record['oid'] is empty) the local object data, given the salesforce object_record.

1 call to sf_notifications_update_record()
_sf_notifications_handle_message in sf_notifications/sf_notifications.module
Loop through an array of SObjects from Salesforce and save them according to any existing sf fieldmaps, notification settings, and data.

File

sf_notifications/sf_notifications.module, line 343

Code

function sf_notifications_update_record($object_record) {
  $success = TRUE;
  $drupal_entity = $object_record['drupal_entity'];
  if (empty($drupal_entity)) {
    $map = salesforce_api_salesforce_fieldmap_load($object_record['name']);
    if (empty($map)) {
      $success = FALSE;
    }
    else {
      $drupal_entity = $map->drupal_entity;
    }
  }

  // Check to see if the drupal_entity is one handled by the sf_entity module.
  $entities = field_info_bundles();
  $entity_names = array_keys($entities);
  if (in_array($drupal_entity, $entity_names)) {
    $function = 'sf_entity_import';
  }
  else {
    $function = 'sf_' . $drupal_entity . '_import';
  }
  if (function_exists($function)) {
    $drupal_id = $function($object_record['fields'], $object_record['name'], $object_record['oid']);
    if ($drupal_id) {
      salesforce_api_log(SALESFORCE_LOG_ALL, 'Salesforce Notifications successful ' . $object_record['operation'] . ' of ' . $drupal_entity . ' ' . $drupal_id);

      // Invoke hook_sf_notifications_processed().
      module_invoke_all('sf_notifications_processed', $object_record['operation'], $object_record, $drupal_id);
    }
    else {
      salesforce_api_log(SALESFORCE_LOG_ALL, 'Salesforce Notifications failed to update ' . $object_record['drupal_entity'] . ' from record.
        <pre>' . print_r($object_record, TRUE) . '</pre>');
      $success = FALSE;
    }
  }
  else {
    salesforce_api_log(SALESFORCE_LOG_ALL, 'Salesforce Notifications: Import handler ' . $function . ' undefined.
        Drupal ' . $object_record['drupal_entity'] . ' with id ' . $object_record['oid'] . ' was not updated.');
    $success = FALSE;
  }
  return $success;
}