You are here

function _sf_notifications_parse_message in Salesforce Suite 7.2

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

Parse SOAP message into its component args.

Parameters

(object) $domDoc: A DOMDocument representation of the outbound SOAP message from Salesforce.

Return value

(array) $matches An array with two sub-arrays, keyed as: 'drupal': A sequential array containing relevant salesforce_ids records. We don't index on drupal_id because there could be overlap. 'salesforce': An indexed array mapping sfids to SObject records from Salesforce.

1 call to _sf_notifications_parse_message()
_sf_notifications_parse_handle_message in sf_notifications/sf_notifications.module
Parses and handles an outbound message from Salesforce.

File

sf_notifications/sf_notifications.module, line 407

Code

function _sf_notifications_parse_message($domDoc) {

  // Needed for the reference to SObject, since the Enterprise Toolkit doesn't have an SObject class.
  require_once DRUPAL_ROOT . '/' . SALESFORCE_DIR_SOAPCLIENT . '/SforcePartnerClient.php';
  $matches = array(
    'salesforce' => array(),
    'drupal' => array(),
  );
  $sfids = array();

  // Create sObject array and fill fields provided in notification
  $objects = $domDoc
    ->getElementsByTagName('sObject');
  foreach ($objects as $sObjectNode) {
    $sObjType = $sObjectNode
      ->getAttribute('xsi:type');
    if (substr_count($sObjType, 'sf:')) {
      $sObjType = substr($sObjType, 3);
    }
    $obj = new SObject();
    $obj->type = $sObjType;
    $elements = $sObjectNode
      ->getElementsByTagNameNS('urn:sobject.enterprise.soap.sforce.com', '*');
    $obj->fieldnames = array();
    foreach ($elements as $node) {
      if ($node->localName == 'Id') {

        // "Id" is a property of the SObject as well as SObject->fields
        $sfids[] = $obj->Id = $node->textContent;
      }
      $fieldname = $node->localName;
      $obj->fields->{$fieldname} = $node->nodeValue;
      array_push($obj->fieldnames, $fieldname);
    }
    $matches['salesforce'][$obj->Id] = $obj;
  }
  $result = db_query('SELECT name, oid, sfid, drupal_entity, drupal_bundle FROM {salesforce_object_map} WHERE sfid IN (:sfids)', array(
    ':sfids' => $sfids,
  ));
  while ($row = $result
    ->fetchAssoc()) {
    $matches['drupal'][] = $row;
  }
  salesforce_api_log(SALESFORCE_LOG_ALL, 'Salesforce Notifications found the following matches for the outbound message: ' . '<pre>' . print_r($matches, TRUE) . '</pre>');
  return $matches;
}