X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContact%2FBAO%2FRelationship.php;h=4411555100b4dbc4bdbe305055ee3c51384de9d6;hb=decc60a0b9dc5b26b2bbc1e4a1e0549b1b722bd1;hp=ec2407a6784c886e72d7fc1155936a7197921866;hpb=95ea96beae31b4dd733c35e09a8c964a6839bb1b;p=civicrm-core.git diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index ec2407a678..4411555100 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -307,9 +307,11 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { if (!empty($params['id'])) { //let's load the missing ids here since other things tend to rely on them. $fieldsToFill = array('contact_id_a', 'contact_id_b', 'relationship_type_id'); - $result = CRM_Core_DAO::executeQuery("SELECT " . implode(',', $fieldsToFill) . " FROM civicrm_relationship WHERE id = %1", array('Integer', $params['id']))->fetchRow(); - foreach ($fieldsToFill as $field) { - $params[$field] = !empty($params[$field]) ? $params[$field] : $result->$field; + $result = CRM_Core_DAO::executeQuery("SELECT " . implode(',', $fieldsToFill) . " FROM civicrm_relationship WHERE id = %1", array(1 => array($params['id'], 'Integer'))); + while ($result->fetch()) { + foreach ($fieldsToFill as $field) { + $params[$field] = !empty($params[$field]) ? $params[$field] : $result->$field; + } } return; } @@ -712,7 +714,7 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { */ public static function checkDuplicateRelationship(&$params, $id, $contactId = 0, $relationshipId = 0) { $relationshipTypeId = CRM_Utils_Array::value('relationship_type_id', $params); - list($type, $first, $second) = explode('_', $relationshipTypeId); + list($type) = explode('_', $relationshipTypeId); $queryString = " SELECT id @@ -1231,7 +1233,7 @@ LEFT JOIN civicrm_country ON (civicrm_address.country_id = civicrm_country.id) */ public static function relatedMemberships($contactId, &$params, $ids, $action = CRM_Core_Action::ADD, $active = TRUE) { // Check the end date and set the status of the relationship - // accrodingly. + // accordingly. $status = self::CURRENT; if (!empty($params['end_date'])) { @@ -1255,7 +1257,14 @@ LEFT JOIN civicrm_country ON (civicrm_address.country_id = civicrm_country.id) $rel = explode('_', $params['relationship_type_id']); $relTypeId = $rel[0]; - $relDirection = "_{$rel[1]}_{$rel[2]}"; + if (!empty($rel[1])) { + $relDirection = "_{$rel[1]}_{$rel[2]}"; + } + else { + // this call is coming from somewhere where the direction was resolved early on (e.g an api call) + // so we can assume _a_b + $relDirection = "_a_b"; + } $targetContact = array(); if (($action & CRM_Core_Action::ADD) || ($action & CRM_Core_Action::DELETE)