Details
-
Type: Bug
-
Status: Done/Fixed
-
Priority: Critical
-
Resolution: Fixed/Completed
-
Affects Version/s: 4.7.13
-
Fix Version/s: 4.7.23
-
Labels:
-
Versioning Impact:Patch (backwards-compatible bug fixes)
-
Documentation Required?:None
-
Funding Source:Core Team Contract
-
Verified?:No
Description
Marking as critical due to data loss / unexpected data results when manually merging.
Setup:
Create a new custom field on contacts, type 'checkbox' with two options: 'Option 1' and 'Option 2'.
Issue 1: Custom values are not overwritten
To recreate:
Duplicate contact has 'Option 2'
Main contact has 'Option 1'
Select to 'take across' Option 2 when manually merging
Expected result: Option 2
Actual result: Option 1 in UI, but both show as selected when going to edit the values (see screenshot)
Discussion: although the code seems to have been written (in places) to 'merge' the two, I think 'overwriting' is the correct default approach. This is seconded by the text in the merge screen which also says 'overwrite' when choosing the value.
Issue 1a: Propose that we change the interface to allow 'overwrite' and 'add' options
To allow flexibility in the merge interface, following a discussion with Jamie, it would make sense to provide 'add' and 'overwrite' options when merging custom fields with multiple values. 'Overwrite' should be the default option.
Issue 2: Custom values migrated even when told not to!
Steps to recreate:
Create a custom checkbox field with two options, '1' and '2'.
Create 'contact main' using the API:
'contact_type' => "Individual", 'last_name' => "Main", 'first_name' => "Contact",
Create 'contact duplicate using the API, including '1' in the custom field:
'contact_type' => "Individual", "last_name": "Duplicate", "first_name": "Contact", "custom_9": 1
Merge the two contacts, with the 'main' contact on the right- do not select anything to take across
Expected result: No custom field value
Actual result: '1' in the custom field
Analysis: Note this only happens if the main contact never had any custom field values assigned (ie: no reference in the database). This seems to stem from the second call to the moveContactBelongings function here: https://github.com/civicrm/civicrm-core/blob/cd86a3ba16f244a9168aeb14cdfc43138e071e66/CRM/Dedupe/Merger.php#L1486 which 'moves' all the custom field values from the duplicate to the main, regardless of what was selected on the form.
This issue is the case with all custom fields, not just checkboxes.