Use getMergedTo in civiimport when the contact has been deleted from trash#36322
Open
larssandergreen wants to merge 1 commit into
Open
Use getMergedTo in civiimport when the contact has been deleted from trash#36322larssandergreen wants to merge 1 commit into
larssandergreen wants to merge 1 commit into
Conversation
|
🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷 Introduction for new contributors...
PR commands & links...
|
larssandergreen
force-pushed
the
mergedto_civiiimport
branch
from
July 24, 2026 20:37
45aa3d8 to
7b183a4
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Before
If you import with civiimport to a contact id that was merged away and then deleted from trash, you'll get an import error.
After
Import will be to the merged to contact for the deleted contact, assuming the merge happened after #36290.
Technical Details
No change to importing contacts.
In order to make this work, I re-ordered operations so that we check for a merged to contact before validating the contact type, which makes more sense since we care about the contact type of the contact we are actually importing to not the original contact id (though it would be rare that they differed).
This re-ordering also fixes the rare case where you were importing with both contact id and external id and your external id had been moved to a new contact by merging (previously you got an error, now it imports to the new contact as expected).
I maintained the two different exceptions for slightly different cases: 1) you're trying to import to a contact id that's in the trash and wasn't merged to another contact and 2) you're trying to import to a contact id that doesn't exist at all and wasn't merged to another contact. Not sure if we need two, but this maintains existing behaviour.