fixes for duplicate relationship error, CRM-14352
authorkurund <kurund@civicrm.org>
Thu, 10 Apr 2014 04:31:36 +0000 (21:31 -0700)
committerkurund <kurund@civicrm.org>
Thu, 10 Apr 2014 04:31:36 +0000 (21:31 -0700)
----------------------------------------
* 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

index 2085564ad34920047c25af67883983c38c8016d6..1dda456ab84050564769300e838b91d2f547e012 100644 (file)
@@ -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);