From eabf1c298480ab34e5d0c580fe54945e57cfb024 Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Fri, 23 Aug 2019 15:31:10 +0100 Subject: [PATCH] Fix hardcoded ID for Head of Household relationship --- CRM/Contact/BAO/Relationship.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index fc33ee7ef6..c8a6d98dad 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -329,8 +329,17 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { // check if the relationship type is Head of Household then update the // household's primary contact with this contact. - if ($relationshipTypeID == 6) { - CRM_Contact_BAO_Household::updatePrimaryContact($relationship->contact_id_b, $relationship->contact_id_a); + try { + $headOfHouseHoldID = civicrm_api3('RelationshipType', 'getvalue', [ + 'return' => "id", + 'name_a_b' => "Head of Household for", + ]); + if ($relationshipTypeID == $headOfHouseHoldID) { + CRM_Contact_BAO_Household::updatePrimaryContact($relationship->contact_id_b, $relationship->contact_id_a); + } + } + catch (Exception $e) { + // No "Head of Household" relationship found so we skip specific processing } if (!empty($params['id']) && self::isCurrentEmployerNeedingToBeCleared($relationship->toArray(), $params['id'], $relationshipTypeID)) { -- 2.25.1