-
-
Notifications
You must be signed in to change notification settings - Fork 827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dev/core#1109 - Fix merge not updating ContactReference fields #14983
Merged
eileenmcnaughton
merged 1 commit into
civicrm:master
from
greenpeace-cee:fix-contact-reference-merge
Aug 8, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -800,6 +800,67 @@ public function testMigrationOfSomeCustomDataOnEmptyCustomRecord() { | |
$this->callAPISuccess('CustomGroup', 'delete', ['id' => $multiGroup['id']]); | ||
} | ||
|
||
/** | ||
* Test that ContactReference fields are updated to point to the main contact | ||
* after a merge is performed and the duplicate contact is deleted. | ||
*/ | ||
public function testMigrationOfContactReferenceCustomField() { | ||
// Create Custom Fields | ||
$contactGroup = $this->setupCustomGroupForIndividual(); | ||
$activityGroup = $this->customGroupCreate([ | ||
'name' => 'test_group_activity', | ||
'extends' => 'Activity', | ||
]); | ||
$refFieldContact = $this->customFieldCreate([ | ||
'custom_group_id' => $contactGroup['id'], | ||
'label' => 'field_1' . $contactGroup['id'], | ||
'data_type' => 'ContactReference', | ||
'default_value' => NULL, | ||
]); | ||
$refFieldActivity = $this->customFieldCreate([ | ||
'custom_group_id' => $activityGroup['id'], | ||
'label' => 'field_1' . $activityGroup['id'], | ||
'data_type' => 'ContactReference', | ||
'default_value' => NULL, | ||
]); | ||
|
||
// Contacts setup | ||
$this->setupMatchData(); | ||
$originalContactID = $this->contacts[0]['id']; | ||
$duplicateContactID = $this->contacts[1]['id']; | ||
|
||
// create a contact that won't be merged but has a ContactReference field | ||
// pointing to the duplicate (to be deleted) contact | ||
$unrelatedContact = $this->individualCreate([ | ||
'first_name' => 'Unrelated', | ||
'first_name' => 'Contact', | ||
'email' => 'unrelated@example.com', | ||
"custom_{$refFieldContact['id']}" => $duplicateContactID, | ||
]); | ||
// also create an activity with a ContactReference custom field | ||
$activity = $this->activityCreate([ | ||
'target_contact_id' => $unrelatedContact, | ||
"custom_{$refFieldActivity['id']}" => $duplicateContactID, | ||
]); | ||
|
||
// verify that the fields were set | ||
$this->assertCustomFieldValue($unrelatedContact, $duplicateContactID, "custom_{$refFieldContact['id']}"); | ||
$this->assertEntityCustomFieldValue('Activity', $activity['id'], $duplicateContactID, "custom_{$refFieldActivity['id']}_id"); | ||
|
||
// Perform merge | ||
$this->mergeContacts($originalContactID, $duplicateContactID, []); | ||
|
||
// verify that the ContactReference fields were updated to point to the surviving contact post-merge | ||
$this->assertCustomFieldValue($unrelatedContact, $originalContactID, "custom_{$refFieldContact['id']}"); | ||
$this->assertEntityCustomFieldValue('Activity', $activity['id'], $originalContactID, "custom_{$refFieldActivity['id']}_id"); | ||
|
||
// cleanup created custom set | ||
$this->callAPISuccess('CustomField', 'delete', ['id' => $refFieldContact['id']]); | ||
$this->callAPISuccess('CustomGroup', 'delete', ['id' => $contactGroup['id']]); | ||
$this->callAPISuccess('CustomField', 'delete', ['id' => $refFieldActivity['id']]); | ||
$this->callAPISuccess('CustomGroup', 'delete', ['id' => $activityGroup['id']]); | ||
} | ||
|
||
/** | ||
* Calls merge method on given contacts, with values given in $params array. | ||
* | ||
|
@@ -835,8 +896,21 @@ private function mergeContacts($originalContactID, $duplicateContactID, $params) | |
* @param $customFieldName | ||
*/ | ||
private function assertCustomFieldValue($contactID, $expectedValue, $customFieldName) { | ||
$data = $this->callAPISuccess('Contact', 'getsingle', [ | ||
'id' => $contactID, | ||
$this->assertEntityCustomFieldValue('Contact', $contactID, $expectedValue, $customFieldName); | ||
} | ||
|
||
/** | ||
* Check if the custom field of the given field and entity id matches the | ||
* expected value | ||
* | ||
* @param $entity | ||
* @param $id | ||
* @param $expectedValue | ||
* @param $customFieldName | ||
*/ | ||
private function assertEntityCustomFieldValue($entity, $id, $expectedValue, $customFieldName) { | ||
$data = $this->callAPISuccess($entity, 'getsingle', [ | ||
'id' => $id, | ||
'return' => [$customFieldName], | ||
]); | ||
|
||
|
@@ -918,7 +992,7 @@ public function setupMatchData() { | |
foreach ($fixtures as $fixture) { | ||
$contactID = $this->individualCreate($fixture); | ||
$this->contacts[] = array_merge($fixture, ['id' => $contactID]); | ||
sleep(5); | ||
sleep(2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be enough? |
||
} | ||
$organizationFixtures = [ | ||
[ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NFC - just a bit more defensive as it doesn't muck things up if the call order is changed.