From 0782c7b9321591b43bb46ae698dc71224ad50672 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 26 Feb 2018 17:00:30 +1300 Subject: [PATCH] Fix relationshipType api --- CRM/Contact/BAO/RelationshipType.php | 7 +++--- api/v3/RelationshipType.php | 23 ++++--------------- .../phpunit/api/v3/SyntaxConformanceTest.php | 1 - 3 files changed, 7 insertions(+), 24 deletions(-) diff --git a/CRM/Contact/BAO/RelationshipType.php b/CRM/Contact/BAO/RelationshipType.php index 5ddec3cdb8..656e27f62e 100644 --- a/CRM/Contact/BAO/RelationshipType.php +++ b/CRM/Contact/BAO/RelationshipType.php @@ -85,7 +85,8 @@ class CRM_Contact_BAO_RelationshipType extends CRM_Contact_DAO_RelationshipType * * @return CRM_Contact_DAO_RelationshipType */ - public static function add(&$params, &$ids) { + public static function add(&$params, $ids = []) { + $params['id'] = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('relationshipType', $ids)); //to change name, CRM-3336 if (empty($params['label_a_b']) && !empty($params['name_a_b'])) { $params['label_a_b'] = $params['name_a_b']; @@ -97,7 +98,7 @@ class CRM_Contact_BAO_RelationshipType extends CRM_Contact_DAO_RelationshipType // set label to name if it's not set - but *only* for // ADD action. CRM-3336 as part from (CRM-3522) - if (empty($ids['relationshipType'])) { + if (!$params['id']) { if (empty($params['name_a_b']) && !empty($params['label_a_b'])) { $params['name_a_b'] = $params['label_a_b']; } @@ -119,8 +120,6 @@ class CRM_Contact_BAO_RelationshipType extends CRM_Contact_DAO_RelationshipType $relationshipType->label_b_a = CRM_Utils_Array::value('label_a_b', $params); } - $relationshipType->id = CRM_Utils_Array::value('relationshipType', $ids); - $result = $relationshipType->save(); CRM_Core_PseudoConstant::relationshipType('label', TRUE); diff --git a/api/v3/RelationshipType.php b/api/v3/RelationshipType.php index 4260edc42c..b7aa1d34c8 100644 --- a/api/v3/RelationshipType.php +++ b/api/v3/RelationshipType.php @@ -41,31 +41,16 @@ */ function civicrm_api3_relationship_type_create($params) { - if (!isset($params['label_a_b'])) { - + // @todo should we when id is empty? + if (!isset($params['label_a_b']) && !empty($params['name_a_b'])) { $params['label_a_b'] = $params['name_a_b']; } - if (!isset($params['label_b_a'])) { - + if (!isset($params['label_b_a']) && !empty($params['name_b_a'])) { $params['label_b_a'] = $params['name_b_a']; } - $ids = array(); - if (isset($params['id']) && !CRM_Utils_Rule::integer($params['id'])) { - return civicrm_api3_create_error('Invalid value for relationship type ID'); - } - else { - $ids['relationshipType'] = CRM_Utils_Array::value('id', $params); - } - - $relationType = CRM_Contact_BAO_RelationshipType::add($params, $ids); - - $relType = array(); - - _civicrm_api3_object_to_array($relationType, $relType[$relationType->id]); - - return civicrm_api3_create_success($relType, $params, 'RelationshipType', 'create', $relationType); + return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'RelationshipType'); } /** diff --git a/tests/phpunit/api/v3/SyntaxConformanceTest.php b/tests/phpunit/api/v3/SyntaxConformanceTest.php index 32f9b525a0..1274ddad78 100644 --- a/tests/phpunit/api/v3/SyntaxConformanceTest.php +++ b/tests/phpunit/api/v3/SyntaxConformanceTest.php @@ -396,7 +396,6 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { 'PledgePayment', 'PaymentProcessorType', 'Relationship', - 'RelationshipType', // ones that are not real entities hence not extendable. 'ActivityType', -- 2.25.1