Fix import falling over when a note is included
authorEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 7 Jul 2022 22:21:46 +0000 (10:21 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 7 Jul 2022 22:21:46 +0000 (10:21 +1200)
CRM/Contact/Import/Parser/Contact.php
tests/phpunit/CRM/Contact/Import/Form/data/individual_with_note.csv [new file with mode: 0644]
tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php

index 3b2c0a5af12a91aa95b71fad0c93253d282ca670..b85f3c5afc43e022372c9c0dd800f0482264b8b7 100644 (file)
@@ -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 (file)
index 0000000..1ee82a4
--- /dev/null
@@ -0,0 +1,2 @@
+First Name,Last Name,Note
+Mr, Jones,Kinda dull
index 1535c5cfaba86dedb50bc2b9899c3a6f8a7c747e..b9392c3653023164c1433e62f4f8f097f647a822 100644 (file)
@@ -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']],