CRM-16055 further fix on setting relationship fields
authorEileen McNaughton <eileen@fuzion.co.nz>
Mon, 16 Mar 2015 04:24:20 +0000 (17:24 +1300)
committerEileen McNaughton <eileen@fuzion.co.nz>
Mon, 16 Mar 2015 12:35:32 +0000 (01:35 +1300)
CRM/Contact/BAO/Contact/Utils.php
CRM/Contact/BAO/Relationship.php

index 6ca74ba3a550ca5d8827a1cb7e957986d74cb97e..b1dc5f318d2eb3bd0b2f2fb75517af14a2005a94 100644 (file)
@@ -346,7 +346,7 @@ UNION
       self::setCurrentEmployer(array($contactID => $organization));
 
       $relationshipParams['relationship_ids'] = $relationshipIds;
-      // handle related meberships. CRM-3792
+      // Handle related memberships. CRM-3792
       self::currentEmployerRelatedMembership($contactID, $organization, $relationshipParams, $duplicate, $previousEmployerID);
     }
   }
index 691d2cf0e7cb49ca31eb84abd1d3dab03a8d7151..0e9fc92037aa493de35455569a3c9630ecb0063f 100644 (file)
@@ -149,7 +149,6 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
     $valid = $invalid = $duplicate = $saved = 0;
     $relationships = $relationshipIds = array();
     $relationshipId = CRM_Utils_Array::value('relationship', $ids, CRM_Utils_Array::value('id', $params));
-    echo 'relationship id is ' . $relationshipId . "\n";
 
     //CRM-9015 - the hooks are called here & in add (since add doesn't call create)
     // but in future should be tidied per ticket
@@ -177,7 +176,8 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
         // step 3: if valid relationship then add the relation and keep the count
 
         // step 1
-        $errors = self::checkValidRelationship($params, $ids, $key);
+        $contactFields = self::setContactABFromIDs($params, $ids, $key);
+        $errors = self::checkValidRelationship($contactFields, $ids, $key);
         if ($errors) {
           $invalid++;
           continue;
@@ -185,7 +185,7 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
 
         if (
         self::checkDuplicateRelationship(
-          $params,
+          $contactFields,
           CRM_Utils_Array::value('contact', $ids),
           // step 2
           $key
@@ -194,7 +194,7 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
           $duplicate++;
           continue;
         }
-        $contactFields = self::setContactABFromIDs($params, $ids, $key);
+
         $singleInstanceParams = array_merge($params, $contactFields);
         $relationship = self::add($singleInstanceParams);
         $relationshipIds[] = $relationship->id;
@@ -420,12 +420,11 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
       }
       throw new CRM_Core_Exception('Cannot create relationship, insufficient contact IDs provided');
     }
-    if (!is_numeric($params['relationship_type_id'])) {
+    if (isset($params['relationship_type_id']) && !is_numeric($params['relationship_type_id'])) {
       $relationshipTypes = CRM_Utils_Array::value('relationship_type_id', $params);
       list($relationshipTypeID, $first) = explode('_', $relationshipTypes);
-      if (empty($params['relationship_type_id'])) {
-        $returnFields['relationship_type_id'] = $relationshipTypeID;
-      }
+      $returnFields['relationship_type_id'] = $relationshipTypeID;
+
       foreach (array('a', 'b') as $contactLetter) {
         if (empty($params['contact_' . $contactLetter])) {
           if ($first == $contactLetter) {