Fix Contribution Transfer During Contact Merge#35521
Open
shahrukh-compuco wants to merge 1 commit intocivicrm:masterfrom
Open
Fix Contribution Transfer During Contact Merge#35521shahrukh-compuco wants to merge 1 commit intocivicrm:masterfrom
shahrukh-compuco wants to merge 1 commit intocivicrm:masterfrom
Conversation
|
🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷 Introduction for new contributors...
Quick links for reviewers...
|
shahrukh-compuco
added a commit
to compucorp/civicrm-core
that referenced
this pull request
Apr 28, 2026
shahrukh-compuco
added a commit
to compucorp/civicrm-core
that referenced
this pull request
Apr 29, 2026
shahrukh-compuco
added a commit
to compucorp/civicrm-core
that referenced
this pull request
Apr 29, 2026
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.
Overview
When two contacts are merged,
civicrm_contribution.contact_idis currently rewritten to the surviving contact for every contribution attached to the deleted contact's participants, memberships, or pledges — regardless of who originally paid. This silently destroys the link between the contribution and its real payer whenever a third party (employer organisation, parent, sibling, friend, anonymous benefactor, etc.) paid on behalf of the contact being merged.This PR scopes that rewrite to contributions actually paid by the contact being deleted. Third-party-paid contributions now stay attached to their original payer after the merge.
Before
In
CRM_Dedupe_Merger::paymentSql(), each of the threeUPDATEstatements (pledge / membership / participant variants) had aWHEREclause that filtered only on the bridge entity'scontact_id:Because the
WHEREonly checked who the participant was — never who the payer was — every contribution attached to the deleted contact's participation got rewritten to the surviving contact, even when that contribution had originally been paid by a different contact entirely.After
paymentSql()addsAND contribution.contact_id = $otherContactIdto each WHERE` clause:Behaviour matrix for the participant case (membership and pledge are
identical in shape):
otherIdotherIdmainId(unchanged)otherIdotherIdpaymentSql()(already correct under the bridge filter)otherIdmainId