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

Remove deprecation from a hook that's actually uniquely useful #25628

Merged

Conversation

highfalutin
Copy link
Contributor

Overview

hook_civicrm_merge has a sub-hook cidRefs, documented here. This subhook has been deprecated since 2018 (@eileenmcnaughton) -- see the code change and the documentation change.

I'm glad the sub-hook was never removed after it was deprecated, because it actually offers something that hook_civicrm_entityTypes (the suggested replacement) does not: an opportunity to prevent an entity from being merged along with its associated Contact.

cidRefs is invoked only in the context of a merge, and there are some times when that's very helpful. I have a Flag entity that's joined to the Contact entity. In most contexts, I want the Flag's FK to civicrm_contact to behave as usual: the join should be accessible through API4 so that you can get the Contact for a Flag and the Flags for a Contact; a Flag should be cascade-deleted when its Contact is deleted. But, in my use case, Flags should not be reassigned when a Contact is merged into another Contact. The cidRefs sub-hook lets me do this by simply writing

function flagger_civicrm_merge($type, &$data, $idBeingKept = NULL, $idBeingDeleted = NULL, $tables = NULL) {
    if ('cidRefs' === $type) {
        unset($data['civicrm_flag']);
    }
}

entityTypes is a more blunt instrument. I can't accomplish what I want to do with entityTypes or with any hook besides cidRefs, to my knowledge.

Before

If you use the cidRefs phase of hook_civicrm_merge, you get a deprecation notice in your logs.

After

Nice control over the contact merge process, in peace and quiet.

@civibot
Copy link

civibot bot commented Feb 20, 2023

(Standard links)

@civibot civibot bot added the master label Feb 20, 2023
@aydun
Copy link
Contributor

aydun commented Jun 1, 2023

@eileenmcnaughton Any thoughts on this one? You've been doing a lot with merging.

@eileenmcnaughton
Copy link
Contributor

@aydun @highfalutin I was kinda hoping to put in a new hook that would meet your needs - but I see I haven't gotten to it - so yes I will merge this now & not hold it hostage to my good intentions

@eileenmcnaughton eileenmcnaughton merged commit be0b134 into civicrm:master Jun 1, 2023
@highfalutin
Copy link
Contributor Author

Thank you!!! (and thanks for the nudge @aydun)

@highfalutin highfalutin deleted the undeprecate-cidRefs-merge-hook branch October 3, 2023 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants