dev/core#4227 Fix import to not blank birth_date etc on update
authorEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 8 May 2023 05:37:57 +0000 (17:37 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 8 May 2023 05:41:30 +0000 (17:41 +1200)
CRM/Contact/Import/Parser/Contact.php
tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php

index 1e5dd16620e359179df36028e2a2a83dd1d0166a..8aed047023554ca30293de85c579e958901c9ae9 100644 (file)
@@ -306,6 +306,7 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser {
       if ($customFieldID &&
         !array_key_exists($customFieldID, $addressCustomFields)
       ) {
+        // @todo - this can probably go....
         if ($customFields[$customFieldID]['data_type'] == 'Boolean') {
           if (empty($val) && !is_numeric($val) && $this->isFillDuplicates()) {
             //retain earlier value when Import mode is `Fill`
@@ -816,12 +817,10 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser {
           }
         }
       }
-      if (in_array($key, ['nick_name', 'job_title', 'middle_name', 'birth_date', 'gender_id', 'current_employer', 'prefix_id', 'suffix_id'])
-        && ($value == '' || !isset($value)) &&
-        ($session->get('authSrc') & (CRM_Core_Permission::AUTH_SRC_CHECKSUM + CRM_Core_Permission::AUTH_SRC_LOGIN)) == 0 ||
-        ($key === 'current_employer' && empty($params['current_employer']))) {
-        // CRM-10128: if auth source is not checksum / login && $value is blank, do not fill $data with empty value
-        // to avoid update with empty values
+      // Why only these fields...?
+      if ($value === '' && in_array($key, ['nick_name', 'job_title', 'middle_name', 'birth_date', 'gender_id', 'current_employer', 'prefix_id', 'suffix_id'], TRUE)
+        ) {
+        // CRM-10128: if $value is blank, do not fill $data with empty value
         continue;
       }
       else {
index 732d00bbec4941c51a8b610a25a341310b10f723..98294948ab50f9684770d76f606f6abd34d34db7 100644 (file)
@@ -434,11 +434,9 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
     [$originalValues, $result] = $this->setUpBaseContact([
       'external_identifier' => '',
       'email' => NULL,
+      'birth_date' => '2008-01-07',
     ]);
-    $updateValues = ['id' => $result['id'], 'email' => 'bill@example.com'];
-    // This is some deep weirdness - this sets a flag for updatingBlankLocinfo - allowing input to be blanked
-    // (which IS a good thing but it's pretty weird & all to do with legacy profile stuff).
-    CRM_Core_Session::singleton()->set('authSrc', CRM_Core_Permission::AUTH_SRC_CHECKSUM);
+    $updateValues = ['id' => (int) $result['id'], 'email' => 'bill@example.com', 'birth_date' => ''];
     $this->runImport($updateValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID);
     $originalValues['id'] = $result['id'];
     $this->callAPISuccessGetSingle('Email', ['contact_id' => $originalValues['id'], 'is_primary' => 1]);