Eileen has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/379467 )
Change subject: When updating an email return early on email match & set on_hold otherwise. ...................................................................... When updating an email return early on email match & set on_hold otherwise. Bug: T170350 Change-Id: If092a9131c85d5ec332818d1eb9984142c1c3dda --- M sites/all/modules/wmf_civicrm/wmf_civicrm.module 1 file changed, 25 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm refs/changes/67/379467/1 diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.module b/sites/all/modules/wmf_civicrm/wmf_civicrm.module index dc81149..242d328 100644 --- a/sites/all/modules/wmf_civicrm/wmf_civicrm.module +++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.module @@ -1408,16 +1408,33 @@ try { $loc_type_id = isset($msg['email_location_type_id']) ? $msg['email_location_type_id'] : wmf_civicrm_get_default_location_type_id(); $isPrimary = isset($msg['email_location_type_id']) ? 0 : 1; - civicrm_api3( "Email", "Replace", array( - 'debug' => 1, + + $emailParams = array( + 'email' => $msg['email'], + 'is_primary' => $isPrimary, + 'is_billing' => $isPrimary, + ); + + // Look up contact's existing email to get the id and to determine + // if the email has changed. + $existingEmails = civicrm_api3( "Email", 'get', array( 'location_type_id' => $loc_type_id, 'contact_id' => $contact_id, - 'values' => array(array( - 'email' => $msg[ 'email' ], - 'is_primary' => $isPrimary, - 'is_billing' => $isPrimary, - ), - ))); + 'sequential' => 1, + )); + + if ($existingEmails['count']) { + $existingEmail = $existingEmails['values'][0]; + if ($existingEmail['email'] === $msg['email']) { + // A case could be made for ensuring isPrimary / isBilling it set + // but unclear if the incoming would necesarily be more primary/billingy + return; + } + $emailParams['id'] = $existingEmail['id']; + $emailParams['on_hold'] = 0; + } + + civicrm_api3( "Email", "create", $emailParams); } catch (CiviCRM_API3_Exception $e) { throw new WmfException( 'IMPORT_CONTACT', "Couldn't store email for the contact.", $e->getExtraParams()); -- To view, visit https://gerrit.wikimedia.org/r/379467 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If092a9131c85d5ec332818d1eb9984142c1c3dda Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/crm Gerrit-Branch: master Gerrit-Owner: Eileen <emcnaugh...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits