From 80109b10409c521b8c3b74ef1133c907631f5f52 Mon Sep 17 00:00:00 2001 From: kurund Date: Wed, 9 Apr 2014 21:31:36 -0700 Subject: [PATCH] fixes for duplicate relationship error, CRM-14352 ---------------------------------------- * CRM-14352: Fatal error: Relationship already exists when contact with duplicate relationships registers for an event https://issues.civicrm.org/jira/browse/CRM-14352 --- CRM/Contact/BAO/Relationship.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index 2085564ad3..1dda456ab8 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -747,7 +747,15 @@ WHERE relationship_type_id = " . CRM_Utils_Type::escape($type, 'Integer'); // however, a longer term solution would be to simplify the add, create & api functions // to be more standard. It is debatable @ that point whether it's better to call the BAO // direct as the api is more tested. - civicrm_api3('relationship', 'create', array('id' => $id, 'is_active' => $is_active)); + $result = civicrm_api('relationship', 'create', array( + 'id' => $id, + 'is_active' => $is_active, + 'version' => 3, + )); + + if (is_array($result) && !empty($result['is_error']) && $result['error_message'] != 'Relationship already exists') { + throw new CiviCRM_API3_Exception($result['error_message'], CRM_Utils_Array::value('error_code', $result, 'undefined'), $result); + } // call (undocumented possibly deprecated) hook CRM_Utils_Hook::enableDisable('CRM_Contact_BAO_Relationship', $id, $is_active); -- 2.25.1