1

Today I realized that our installation holds many individuals without an address. Most of them are employees and correctly related to their employer. So I decided to use the api to let all them share the address of their organization. Once done, I saw that the works-for-relationships are doubled.

A glance into the code told me that CRM_Core_BAO_Address calls it's processSharedAddressRelationship() method on address creation and this references CRM_Contact_BAO_Relationship::checkDuplicateRelationship. This is what I expected. But it did not detect our existing relationships because for whatever reason it checks if the custom fields of existing relationships are given in the params array for the new relationship:

#923 $result = self::checkDuplicateCustomFields($params, $relationship->id);

And AFAICS the approach can't work properly because CRM_Core_BAO_Address creates the params for the relationship:

$relParam = array(
  'is_active' => TRUE,
  'relationship_type_id' => $relTypeId,
  'contact_id_a' => $currentContactId,
  'contact_id_b' => $sharedContactId,
);

// If already there is a relationship record of $relParam criteria, avoid creating relationship again or else
// it will casue CRM-16588 as the Duplicate Relationship Exception will revert other contact field values on update
if (CRM_Contact_BAO_Relationship::checkDuplicateRelationship($relParam, $currentContactId, $sharedContactId)) {
  return;
}

So the $relParam could never include custom fields checked in CRM_Contact_BAO_Relationship::checkDuplicateRelationship

public static function checkDuplicateRelationship(&$params, $id, $contactId = 0, $relationshipId = 0) {
  [....]
  $result = self::checkDuplicateCustomFields($params, $relationship->id);

but there this array is compared with the existing relationship.

Why is this?

I'll fix this locally but I don't understand what's going on...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.