Commit 937b554b authored by B_man's avatar B_man
Browse files

Add salesforce query to check for UID on contact to prevent circular syncing

parent 882ebbec
......@@ -6549,14 +6549,29 @@ function drupalorg_user_update(&$edit, $account) {
* @throws SalesforcePullException
*/
function drupalorg_salesforce_pull_entity_update($account, $sf_object, $sf_mapping) {
// Query salesforce to check and see if a salesforce contact has a drupal.org UID
try {
$salesforce = salesforce_get_api();
$query = new SalesforceSelectQuery('contact');
$query->addCondition('Id', "'" . $sf_object['Id'] . "'", '=');
$query->fields = [
"Id" => "Id",
"Name" => "Name",
"Drupal_uid_int__c" => 'Drupal_uid_int__c',
];
$query_results = $salesforce->query($query);
} catch (SalesforceException $e) {
watchdog('drupalorg salesforce pull', 'Salesforce pull for @name errored: @error', ['@name' => $account->name, '@error' => $e->getMessage()], WATCHDOG_ERROR);
}
// If a salesforce contact has a drupal.org UID, don't bother pushing a UID to salesforce
$wrapper = entity_metadata_wrapper('user', $account);
if ($wrapper->field_da_ind_membership->value()) {
if (empty($query_results['records'][0]['Drupal_uid_int__c']) && $wrapper->field_da_ind_membership->value()) {
$entity_type = 'user';
$entity = $account;
$sf_sync_trigger = SALESFORCE_MAPPING_SYNC_DRUPAL_UPDATE;
$mapping = salesforce_mapping_load('uidpush');
$sf_push = salesforce_push_sync_rest($entity_type, $entity, $mapping, $sf_sync_trigger);
watchdog('drupalorg Salesforce Push', 'Salesforce push for @name', ['@name' => $account->name], WATCHDOG_INFO);
watchdog('drupalorg salesforce push', 'Salesforce push for @name', ['@name' => $account->name], WATCHDOG_INFO);
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment