From decc60a0b9dc5b26b2bbc1e4a1e0549b1b722bd1 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 7 Jan 2015 02:05:17 +1300 Subject: [PATCH] CRM-15781 further tidy-ups --- CRM/Contact/BAO/Relationship.php | 21 +++++++++++++++------ api/v3/Phone.php | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) 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) diff --git a/api/v3/Phone.php b/api/v3/Phone.php index 86c9e4b42b..e207f840a8 100644 --- a/api/v3/Phone.php +++ b/api/v3/Phone.php @@ -49,7 +49,7 @@ * @access public */ function civicrm_api3_phone_create($params) { - return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); + return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Phone'); } /** -- 2.25.1