Skip to content
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

Conversation

pfigel
Copy link
Contributor

@pfigel pfigel commented Aug 7, 2019

Overview

When duplicates are merged, custom fields and other records pointing to the duplicate contact (i.e. the one that will be deleted) should be redirected to the main (surviving) contact.

Before

When a custom field of type ContactReference exists, and values point to a contact used as the duplicate when merging, these records will not be updated to point to the main contact.

After

ContactReference custom fields are updated to point to the main contact.

Technical Details

CRM_Core_DAO::getReferencesToContactTable(), which was updated to include ContactReference fields, is also used by some logging features, including CRM_Logging_ReportDetail. Logging code generally has okay test coverage and I've manually tested some bits in the report.

This fixes an issue that causes ContactReference custom fields pointing
to a duplicated contact that's being merged to not be updated to the
main (surviving) contact.
@civibot
Copy link

civibot bot commented Aug 7, 2019

(Standard links)

@civibot civibot bot added the master label Aug 7, 2019
@@ -2398,7 +2399,26 @@ public static function appendCustomTablesExtendingContacts(&$cidRefs) {
$customValueTables = CRM_Core_BAO_CustomGroup::getAllCustomGroupsByBaseEntity('Contact');
$customValueTables->find();
while ($customValueTables->fetch()) {
$cidRefs[$customValueTables->table_name] = ['entity_id'];
$cidRefs[$customValueTables->table_name][] = 'entity_id';
Copy link
Contributor Author

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.

@@ -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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be enough?

@eileenmcnaughton
Copy link
Contributor

I stepped through this test in debugger & it all makes sense & I agree that this data should be migrated - merging

@eileenmcnaughton eileenmcnaughton merged commit 65cdcd6 into civicrm:master Aug 8, 2019
@pfigel
Copy link
Contributor Author

pfigel commented Aug 8, 2019

Thanks @eileenmcnaughton!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants