Fixes core#4269 - import 'fill' doesn't work on phone/email
authorJon Goldberg <jon@megaphonetech.com>
Wed, 3 May 2023 18:09:53 +0000 (14:09 -0400)
committerJon Goldberg <jon@megaphonetech.com>
Wed, 3 May 2023 18:28:06 +0000 (14:28 -0400)
CRM/Contact/Import/Parser/Contact.php
tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php

index b9c3f95bdd4f94fa7b0f17c42c642b8a96913eb1..868efc3336cf709c740f332a0c9fc18155971abc 100644 (file)
@@ -870,6 +870,8 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser {
 
     $contactParams = [
       'contact_id' => $cid,
+      // core#4269 - Don't check relationships for values.
+      'noRelationships' => TRUE,
     ];
 
     $defaults = [];
index 9f3b2d54754c28502cd9ed0428dde714ef3134d2..732d00bbec4941c51a8b610a25a341310b10f723 100644 (file)
@@ -368,6 +368,34 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
 
   }
 
+  /**
+   * Test that importing a phone/email with "Fill" strategy doesn't get related contact info.
+   * See core#4269.
+   *
+   * @throws \Exception
+   */
+  public function testImportFillWithRelatedContact(): void {
+    $anthony = $this->individualCreate();
+    $jon = $this->individualCreate(['first_name' => 'Jon']);
+    Phone::create()
+      ->addValue('contact_id', $jon)
+      ->addValue('location_type_id:label', 'Home')
+      ->addValue('phone', '123-456-7890')
+      ->execute();
+    Relationship::create(FALSE)
+      ->addValue('contact_id_a', $anthony)
+      ->addValue('contact_id_b', $jon)
+      ->addValue('relationship_type_id', 1)
+      ->execute();
+
+    $this->runImport([
+      'id' => $anthony,
+      'phone' => '212-555-1212',
+    ], CRM_Import_Parser::DUPLICATE_FILL, FALSE);
+    $anthonysPhone = $this->callAPISuccessGetSingle('Phone', ['contact_id' => $anthony]);
+    $this->assertEquals('212-555-1212', $anthonysPhone['phone']);
+  }
+
   /**
    * Test import parser will fallback to external identifier.
    *