From 48c441beb2163e8384013d69cf81da22d41adba5 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 8 Jul 2022 10:21:46 +1200 Subject: [PATCH] Fix import falling over when a note is included --- CRM/Contact/Import/Parser/Contact.php | 29 ------------------- .../Import/Form/data/individual_with_note.csv | 2 ++ .../CRM/Contact/Import/Parser/ContactTest.php | 12 +++++++- 3 files changed, 13 insertions(+), 30 deletions(-) create mode 100644 tests/phpunit/CRM/Contact/Import/Form/data/individual_with_note.csv diff --git a/CRM/Contact/Import/Parser/Contact.php b/CRM/Contact/Import/Parser/Contact.php index 3b2c0a5af1..b85f3c5afc 100644 --- a/CRM/Contact/Import/Parser/Contact.php +++ b/CRM/Contact/Import/Parser/Contact.php @@ -1177,35 +1177,6 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { return TRUE; } - // Cache the various object fields - // @todo - remove this after confirming this is just a compilation of other-wise-cached fields. - static $fields = []; - - if (isset($values['note'])) { - // add a note field - if (!isset($params['note'])) { - $params['note'] = []; - } - $noteBlock = count($params['note']) + 1; - - $params['note'][$noteBlock] = []; - if (!isset($fields['Note'])) { - $fields['Note'] = CRM_Core_DAO_Note::fields(); - } - - // get the current logged in civicrm user - $session = CRM_Core_Session::singleton(); - $userID = $session->get('userID'); - - if ($userID) { - $values['contact_id'] = $userID; - } - - _civicrm_api3_store_values($fields['Note'], $values, $params['note'][$noteBlock]); - - return TRUE; - } - // Check for custom field values $customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $values), FALSE, FALSE, NULL, NULL, FALSE, FALSE, FALSE diff --git a/tests/phpunit/CRM/Contact/Import/Form/data/individual_with_note.csv b/tests/phpunit/CRM/Contact/Import/Form/data/individual_with_note.csv new file mode 100644 index 0000000000..1ee82a48ec --- /dev/null +++ b/tests/phpunit/CRM/Contact/Import/Form/data/individual_with_note.csv @@ -0,0 +1,2 @@ +First Name,Last Name,Note +Mr, Jones,Kinda dull diff --git a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php index 1535c5cfab..b9392c3653 100644 --- a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php +++ b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php @@ -1089,12 +1089,16 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { * @throws \CRM_Core_Exception * @throws \League\Csv\CannotInsertRecord */ - public function testImport($csv, $mapper, $expectedOutcomes = [], $submittedValues = []): void { + public function testImport($csv, $mapper, $expectedOutcomes = [], $submittedValues = [], $apiLookup = []): void { $this->importCSV($csv, $mapper, $submittedValues); $dataSource = new CRM_Import_DataSource_CSV(UserJob::get(FALSE)->setSelect(['id'])->execute()->first()['id']); foreach ($expectedOutcomes as $outcome => $count) { $this->assertEquals($dataSource->getRowCount([$outcome]), $count); } + if (!empty($apiLookup)) { + $this->callAPISuccessGetCount($apiLookup['entity'], $apiLookup['params'], $apiLookup['count']); + } + ob_start(); $_REQUEST['user_job_id'] = $dataSource->getUserJobID(); $_REQUEST['status'] = array_key_first($expectedOutcomes); @@ -1133,6 +1137,12 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { */ public function importDataProvider(): array { return [ + 'individual_with_note.csv' => [ + 'csv' => 'individual_with_note.csv', + 'mapper' => [['first_name'], ['last_name'], ['note']], + 'expected_outcomes' => [CRM_Import_Parser::VALID => 1], + 'check' => ['entity' => 'Note', 'params' => ['note' => 'Kinda dull'], 'count' => 1], + ], 'column_names_casing.csv' => [ 'csv' => 'column_names_casing.csv', 'mapper' => [['first_name'], ['last_name'], ['do_not_import'], ['do_not_import'], ['do_not_import'], ['do_not_import']], -- 2.25.1