From 972906b33960dd2126bcb5629faec188f6d1a8f9 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 17 May 2022 16:27:51 +1200 Subject: [PATCH] [Import] Unpack the weird error return --- CRM/Utils/DeprecatedUtils.php | 34 +++++++++++-------- .../Member/Import/Parser/MembershipTest.php | 5 +-- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/CRM/Utils/DeprecatedUtils.php b/CRM/Utils/DeprecatedUtils.php index f2b718c06d2b..4bfe2c71f435 100644 --- a/CRM/Utils/DeprecatedUtils.php +++ b/CRM/Utils/DeprecatedUtils.php @@ -42,27 +42,33 @@ function _civicrm_api3_deprecated_duplicate_formatted_contact($params) { if ($contact->find(TRUE)) { if ($params['contact_type'] != $contact->contact_type) { - return civicrm_api3_create_error("Mismatched contact IDs OR Mismatched contact Types"); + return ['is_error' => 1, 'error_message' => 'Mismatched contact IDs OR Mismatched contact Types']; } - - $error = CRM_Core_Error::createError("Found matching contacts: $contact->id", - CRM_Core_Error::DUPLICATE_CONTACT, - 'Fatal', $contact->id - ); - return civicrm_api3_create_error($error->pop()); + return [ + 'is_error' => 1, + 'error_message' => [ + 'code' => CRM_Core_Error::DUPLICATE_CONTACT, + 'params' => $contact->id, + 'level' => 'Fatal', + 'message' => "Found matching contacts: $contact->id", + ], + ]; } } else { $ids = CRM_Contact_BAO_Contact::getDuplicateContacts($params, $params['contact_type'], 'Unsupervised'); if (!empty($ids)) { - $ids = implode(',', $ids); - $error = CRM_Core_Error::createError("Found matching contacts: $ids", - CRM_Core_Error::DUPLICATE_CONTACT, - 'Fatal', $ids - ); - return civicrm_api3_create_error($error->pop()); + return [ + 'is_error' => 1, + 'error_message' => [ + 'code' => CRM_Core_Error::DUPLICATE_CONTACT, + 'params' => $ids, + 'level' => 'Fatal', + 'message' => 'Found matching contacts: ' . implode(',', $ids), + ], + ]; } } - return civicrm_api3_create_success(TRUE); + return ['is_error' => 0]; } diff --git a/tests/phpunit/CRM/Member/Import/Parser/MembershipTest.php b/tests/phpunit/CRM/Member/Import/Parser/MembershipTest.php index abd90c5c3f6e..4c2ff9bfc3fa 100644 --- a/tests/phpunit/CRM/Member/Import/Parser/MembershipTest.php +++ b/tests/phpunit/CRM/Member/Import/Parser/MembershipTest.php @@ -113,11 +113,8 @@ public function tearDown(): void { /** * Test Import. - * - * @throws \CRM_Core_Exception - * @throws \CiviCRM_API3_Exception */ - public function testImport() { + public function testImport(): void { $this->individualCreate(); $contact2Params = [ 'first_name' => 'Anthonita',