CRM-15781 further tidy-ups
authorEileen McNaughton <eileen@fuzion.co.nz>
Tue, 6 Jan 2015 13:05:17 +0000 (02:05 +1300)
committerEileen McNaughton <eileen@fuzion.co.nz>
Tue, 6 Jan 2015 13:06:07 +0000 (02:06 +1300)
CRM/Contact/BAO/Relationship.php
api/v3/Phone.php

index ec2407a6784c886e72d7fc1155936a7197921866..4411555100b4dbc4bdbe305055ee3c51384de9d6 100644 (file)
@@ -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)
index 86c9e4b42b7b578527f7f30719ea2300cfb7b9d9..e207f840a85e48b332037c2e5a7c0a1455da3133 100644 (file)
@@ -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');
 }
 
 /**