From a7ed7fa691d99f1fff586299624ffa9b750cec30 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 27 May 2022 18:48:37 +1200 Subject: [PATCH] [Import] [Activity] Fix fatal error regression --- CRM/Activity/Import/Parser/Activity.php | 23 +++---------------- .../Activity/Import/Parser/ActivityTest.php | 7 ++---- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/CRM/Activity/Import/Parser/Activity.php b/CRM/Activity/Import/Parser/Activity.php index 5e95f929ee..e626abd022 100644 --- a/CRM/Activity/Import/Parser/Activity.php +++ b/CRM/Activity/Import/Parser/Activity.php @@ -23,8 +23,6 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Import_Parser { protected $_mapperKeys; - private $_contactIdIndex; - /** * Array of successfully imported activity id's * @@ -103,20 +101,6 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Import_Parser { $this->_newActivity = []; $this->setActiveFields($this->_mapperKeys); - - // FIXME: we should do this in one place together with Form/MapField.php - $this->_contactIdIndex = -1; - - $index = 0; - foreach ($this->_mapperKeys as $key) { - switch ($key) { - case 'target_contact_id': - case 'external_identifier': - $this->_contactIdIndex = $index; - break; - } - $index++; - } } /** @@ -186,16 +170,15 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Import_Parser { } } - if ($this->_contactIdIndex < 0) { + if (empty($params['external_identifier']) && empty($params['target_contact_id'])) { // Retrieve contact id using contact dedupe rule. // Since we are supporting only individual's activity import. $params['contact_type'] = 'Individual'; $params['version'] = 3; - $error = _civicrm_api3_deprecated_duplicate_formatted_contact($params); + $matchedIDs = CRM_Contact_BAO_Contact::getDuplicateContacts($params, 'Individual'); - if (CRM_Core_Error::isAPIError($error, CRM_Core_ERROR::DUPLICATE_CONTACT)) { - $matchedIDs = explode(',', $error['error_message']['params'][0]); + if (!empty($matchedIDs)) { if (count($matchedIDs) > 1) { array_unshift($values, 'Multiple matching contact records detected for this row. The activity was not imported'); return CRM_Import_Parser::ERROR; diff --git a/tests/phpunit/CRM/Activity/Import/Parser/ActivityTest.php b/tests/phpunit/CRM/Activity/Import/Parser/ActivityTest.php index de4d09b101..39515dfd59 100644 --- a/tests/phpunit/CRM/Activity/Import/Parser/ActivityTest.php +++ b/tests/phpunit/CRM/Activity/Import/Parser/ActivityTest.php @@ -296,10 +296,7 @@ class CRM_Activity_Import_Parser_ActivityTest extends CiviUnitTestCase { ], 'expected_error' => '', ], - - // @todo This is also inconsistent. The map UI requires target contact - // but import is fine leaving it blank. In general civi is fine with - // a blank target so possibly map UI should not require it. + // a way to find the contact id is required. 15 => [ 'input' => [ 'target_contact_id' => '', @@ -307,7 +304,7 @@ class CRM_Activity_Import_Parser_ActivityTest extends CiviUnitTestCase { 'activity_date_time' => $some_date, 'activity_subject' => 'asubj', ], - 'expected_error' => '', + 'expected_error' => 'No matching Contact found for ()', ], ]; -- 2.25.1