CRM-16055 fix form to work correctly on update action
authorEileen McNaughton <eileen@fuzion.co.nz>
Mon, 16 Mar 2015 11:26:44 +0000 (00:26 +1300)
committerEileen McNaughton <eileen@fuzion.co.nz>
Mon, 16 Mar 2015 12:35:34 +0000 (01:35 +1300)
CRM/Contact/Form/Relationship.php

index 309abd07ddd2e1ae2105d30988614978c1a5d1ef..684ce7e8040cc159156023b417a500c7191c4b02 100644 (file)
@@ -404,8 +404,17 @@ class CRM_Contact_Form_Relationship extends CRM_Core_Form {
 
     // Update mode (always single)
     if ($this->_action & CRM_Core_Action::UPDATE) {
+      $params['id'] = $this->_relationshipId;
       $ids['relationship'] = $this->_relationshipId;
       $relation = CRM_Contact_BAO_Relationship::getRelationshipByID($this->_relationshipId);
+      if ($relation->contact_id_a == $this->_contactId) {
+        $params['contact_id_a'] = $this->_contactId;
+        $params['contact_id_b'] = array($params['related_contact_id']);
+      }
+      else {
+        $params['contact_id_b'] = $this->_contactId;
+        $params['contact_id_a'] = array($params['related_contact_id']);
+      }
       $ids['contactTarget'] = ($relation->contact_id_a == $this->_contactId) ? $relation->contact_id_b : $relation->contact_id_a;
 
       // @todo this belongs in the BAO.
@@ -436,7 +445,7 @@ class CRM_Contact_Form_Relationship extends CRM_Core_Form {
 
     // Save relationships
     $outcome = CRM_Contact_BAO_Relationship::createMultiple($params, $relationshipTypeParts[1]);
-    list($valid, $invalid, $duplicate, $saved, $relationshipIds) = $outcome;
+    $relationshipIds = $outcome['relationship_ids'];
     $this->setMessage($outcome);
 
     // if this is called from case view,