Ejegg has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/387870 )
Change subject: Only update contact on email match too ...................................................................... Only update contact on email match too In case of forwarded emails. T177663 Change-Id: I797571eeb3d66a40abb59cd43727f33df17ffe40 --- M sites/all/modules/wmf_civicrm/tests/phpunit/ImportMessageTest.php M sites/all/modules/wmf_civicrm/wmf_civicrm.module 2 files changed, 84 insertions(+), 17 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm refs/changes/70/387870/1 diff --git a/sites/all/modules/wmf_civicrm/tests/phpunit/ImportMessageTest.php b/sites/all/modules/wmf_civicrm/tests/phpunit/ImportMessageTest.php index a6fb81c..a8eca49 100644 --- a/sites/all/modules/wmf_civicrm/tests/phpunit/ImportMessageTest.php +++ b/sites/all/modules/wmf_civicrm/tests/phpunit/ImportMessageTest.php @@ -687,20 +687,27 @@ } /** - * When we get a contact ID and matching hash, update instead of create new - * @group contactHash + * When we get a contact ID and matching hash and email, update instead of + * creating new contact. */ public function testImportWithContactIdAndHash() { $existingContact = civicrm_api3('Contact', 'Create', array( 'contact_type' => 'Individual', 'first_name' => 'Test', - 'last_name' => 'Es' . mt_rand() + 'last_name' => 'Es' . mt_rand(), )); $this->contact_id = $existingContact['id']; $existingContact = $existingContact['values'][$existingContact['id']]; + $email = 'booboo' . mt_rand() . '@example.org'; civicrm_api3('Email', 'Create', array( 'contact_id' => $this->contact_id, - 'email' => 'booboo' . mt_rand() . '@example.org', + 'email' => $email, + 'location_type_id' => 1, + )); + civicrm_api3('Address', 'Create', array( + 'contact_id' => $this->contact_id, + 'country' => wmf_civicrm_get_country_id('FR'), + 'street_address' => '777 Trompe L\'Oeil Boulevard', 'location_type_id' => 1, )); $msg = array( @@ -709,7 +716,9 @@ 'currency' => 'USD', 'date' => '2017-01-01 00:00:00', 'invoice_id' => mt_rand(), - 'email' => 'newspecialem...@wikimedia.org', + 'country' => 'US', + 'street_address' => '123 42nd St. #321', + 'email' => $email, 'gateway' => 'test_gateway', 'gateway_txn_id' => mt_rand(), 'gross' => '1.25', @@ -717,15 +726,14 @@ ); $contribution = wmf_civicrm_contribution_message_import($msg); $this->assertEquals($existingContact['id'], $contribution['contact_id']); - $email = $this->callAPISuccessGetSingle( - 'Email', array('contact_id' => $existingContact['id'], 'location_type' => 1) + $address = $this->callAPISuccessGetSingle( + 'Address', array('contact_id' => $existingContact['id'], 'location_type' => 1) ); - $this->assertEquals($msg['email'], $email['email']); + $this->assertEquals($msg['street_address'], $address['street_address']); } /** * If we get a contact ID and a bad hash, leave the existing contact alone - * @group contactHash */ public function testImportWithContactIdAndBadHash() { $existingContact = civicrm_api3('Contact', 'Create', array( @@ -733,11 +741,18 @@ 'first_name' => 'Test', 'last_name' => 'Es' . mt_rand() )); + $email = 'booboo' . mt_rand() . '@example.org'; $this->contact_id = $existingContact['id']; $existingContact = $existingContact['values'][$existingContact['id']]; civicrm_api3('Email', 'Create', array( 'contact_id' => $this->contact_id, - 'email' => 'booboo' . mt_rand() . '@example.org', + 'email' => $email, + 'location_type_id' => 1, + )); + civicrm_api3('Address', 'Create', array( + 'contact_id' => $this->contact_id, + 'country' => wmf_civicrm_get_country_id('FR'), + 'street_address' => '777 Trompe L\'Oeil Boulevard', 'location_type_id' => 1, )); $msg = array( @@ -747,7 +762,9 @@ 'currency' => 'USD', 'date' => '2017-01-01 00:00:00', 'invoice_id' => mt_rand(), - 'email' => 'newspecialem...@wikimedia.org', + 'email' => $email, + 'country' => 'US', + 'street_address' => '123 42nd St. #321', 'gateway' => 'test_gateway', 'gateway_txn_id' => mt_rand(), 'gross' => '1.25', @@ -755,10 +772,56 @@ ); $contribution = wmf_civicrm_contribution_message_import($msg); $this->assertNotEquals($existingContact['id'], $contribution['contact_id']); - $email = $this->callAPISuccessGetSingle( - 'Email', array('contact_id' => $existingContact['id'], 'location_type' => 1) + $address = $this->callAPISuccessGetSingle( + 'Address', array('contact_id' => $existingContact['id'], 'location_type' => 1) ); - $this->assertNotEquals($msg['email'], $email['email']); + $this->assertNotEquals($msg['street_address'], $address['street_address']); + } + + /** + * If we get a contact ID and a bad email, leave the existing contact alone + */ + public function testImportWithContactIdAndBadEmail() { + $existingContact = civicrm_api3('Contact', 'Create', array( + 'contact_type' => 'Individual', + 'first_name' => 'Test', + 'last_name' => 'Es' . mt_rand() + )); + $email = 'booboo' . mt_rand() . '@example.org'; + $this->contact_id = $existingContact['id']; + $existingContact = $existingContact['values'][$existingContact['id']]; + civicrm_api3('Email', 'Create', array( + 'contact_id' => $this->contact_id, + 'email' => $email, + 'location_type_id' => 1, + )); + civicrm_api3('Address', 'Create', array( + 'contact_id' => $this->contact_id, + 'country' => wmf_civicrm_get_country_id('FR'), + 'street_address' => '777 Trompe L\'Oeil Boulevard', + 'location_type_id' => 1, + )); + $msg = array( + 'contact_id' => $existingContact['id'], + 'first_name' => 'Lex', + 'contact_hash' => $existingContact['hash'], + 'currency' => 'USD', + 'date' => '2017-01-01 00:00:00', + 'invoice_id' => mt_rand(), + 'email' => 'totally.differ...@example.com', + 'country' => 'US', + 'street_address' => '123 42nd St. #321', + 'gateway' => 'test_gateway', + 'gateway_txn_id' => mt_rand(), + 'gross' => '1.25', + 'payment_method' => 'cc', + ); + $contribution = wmf_civicrm_contribution_message_import($msg); + $this->assertNotEquals($existingContact['id'], $contribution['contact_id']); + $address = $this->callAPISuccessGetSingle( + 'Address', array('contact_id' => $existingContact['id'], 'location_type' => 1) + ); + $this->assertNotEquals($msg['street_address'], $address['street_address']); } /** diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.module b/sites/all/modules/wmf_civicrm/wmf_civicrm.module index 2326ac1..af0ed20 100644 --- a/sites/all/modules/wmf_civicrm/wmf_civicrm.module +++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.module @@ -227,11 +227,15 @@ // the hash before using the existing contact. $existing = civicrm_api3('Contact', 'getSingle', array( 'id' => $msg['contact_id'], - 'return' => 'hash' + 'return' => array('hash', 'email') )); - // If the contact doesn't exist, or the hash doesn't match, make it + // If the contact doesn't exist, or the hash or email doesn't match, make it // look like it's a new-donor message. - if (!$existing || $existing['hash'] !== $msg['contact_hash']) { + if ( + !$existing || + $existing['hash'] !== $msg['contact_hash'] || + $existing['email'] !== $msg['email'] + ) { $msg['contact_id'] = null; unset($msg['contact_hash']); } -- To view, visit https://gerrit.wikimedia.org/r/387870 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I797571eeb3d66a40abb59cd43727f33df17ffe40 Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/crm Gerrit-Branch: master Gerrit-Owner: Ejegg <ej...@ejegg.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits