CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Howto hook into a (contact) merge ?
Pages: [1]

Author Topic: Howto hook into a (contact) merge ?  (Read 663 times)

Cauliflower

  • I’m new here
  • *
  • Posts: 1
  • Karma: 0
  • CiviCRM version: 4.3.4
  • CMS version: Drupal 7.x
  • MySQL version: 5.5
  • PHP version: 5.3
Howto hook into a (contact) merge ?
June 12, 2013, 12:02:10 pm
How can I hook into a merge ?

After merging two contacts I want to do some actions. Is their a way/hook to know which addresses/phones/... are updated, deleted or kept ? I tried the hook_civicrm_post, hook_civicrm_pre or even the hook_merge but I can't get the info I want (eg. the addresses that are changed do not pass these hooks).

Does anyone have a clue ? Thx!

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Howto hook into a (contact) merge ?
June 12, 2013, 01:12:35 pm
The merge is done on a per-object-type basis not a per-object basis. Since in the UI the user gets to choose whether or not to merge addresses, but they don't get to pick and choose particular addresses to merge.
The merge hook will provide you with a list of object types that are going to be merged (and it will fire again after the merge is complete, I think). Look at the core code to see what's actually going on.
But basically your hook code will need to do something like this (pseudocode):
Code: [Select]
if (addresses are going to be included in the query) {
  civicrm_api('address', 'get', array(pass in contact id of the old contact));
}
Try asking your question on the new CiviCRM help site.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Howto hook into a (contact) merge ?

This forum was archived on 2017-11-26.