Index: sf_node/sf_node.module =================================================================== RCS file: /cvs/salesforce/sf_node/sf_node.module,v retrieving revision 1.2 diff -u -r1.2 sf_node.module --- sf_node/sf_node.module 30 Jun 2009 08:46:13 -0000 1.2 +++ sf_node/sf_node.module 2 Jul 2009 01:11:44 -0000 @@ -484,6 +484,18 @@ // Load the fieldmap so we can get the object name. $map = salesforce_api_fieldmap_load($fieldmap); + + $prematch_found = false; + if (empty($sfid)) { + // call hook_sf_find_match to give opportunity to try to match existing sf object instead + // of creating a new one. + $matches = module_invoke_all('sf_find_match', 'export', 'node', $node, $map); + // TODO: handle case where multiple implementers of hook return multiple results. + if (count($matches)) { + $sfid = $matches[0]; + $prematch_found = true; + } + } if (empty($sfid)) { // Export the object to Salesforce. @@ -497,7 +509,8 @@ // If the export was successful... if ($response->success) { - if (empty($sfid)) { + // If this is the first time this drupal object has been exported... + if (empty($sfid) || $prematch_found) { // Store the Salesforce ID for the node and return TRUE. salesforce_api_id_save('node', $node->nid, $response->id, $fieldmap); } Index: sf_user/sf_user.module =================================================================== RCS file: /cvs/salesforce/sf_user/sf_user.module,v retrieving revision 1.2 diff -u -r1.2 sf_user.module --- sf_user/sf_user.module 30 Jun 2009 08:46:13 -0000 1.2 +++ sf_user/sf_user.module 2 Jul 2009 01:14:53 -0000 @@ -334,6 +334,18 @@ // Load the fieldmap so we can get the object name. $map = salesforce_api_fieldmap_load($fieldmap); + + $prematch_found = false; + if (empty($sfid)) { + // call hook_sf_find_match to give opportunity to try to match existing sf object instead + // of creating a new one. + $matches = module_invoke_all('sf_find_match', 'export', 'user', $account, $map); + // TODO: handle case where multiple implementers of hook return multiple results. + if (count($matches)) { + $sfid = $matches[0]; + $prematch_found = true; + } + } if (empty($sfid)) { // Export the object to Salesforce. @@ -347,7 +359,8 @@ // If the export was successful... if ($response->success) { - if (empty($sfid)) { + // If this is the first time this drupal object has been exported... + if (empty($sfid) || $prematch_found) { // Store the Salesforce ID for the node and return TRUE. salesforce_api_id_save('user', $uid, $response->id, $fieldmap); }