Skip to content

Commit

Permalink
Merge pull request #24801 from briennekordis/issue3927
Browse files Browse the repository at this point in the history
Resolve Issue #3927: contact import failure of different related contact typess
  • Loading branch information
eileenmcnaughton authored Oct 24, 2022
2 parents c1b6ed2 + 0e90f8b commit 68a22a1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
15 changes: 14 additions & 1 deletion CRM/Contact/Import/Parser/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Civi\Api4\Contact;
use Civi\Api4\RelationshipType;
use Civi\Api4\StateProvince;
use Civi\Api4\DedupeRuleGroup;

require_once 'api/v3/utils.php';

Expand Down Expand Up @@ -1628,7 +1629,19 @@ protected function lookupContactID(array $params, bool $isMainContact): ?int {
if (isset($params['relationship'])) {
unset($params['relationship']);
}
$id = $this->getPossibleContactMatch($params, $extIDMatch, $this->getSubmittedValue('dedupe_rule_id') ?: NULL);
$ruleId = $this->getSubmittedValue('dedupe_rule_id') ?: NULL;
// if this is not the main contact and the contact types are not the same
$mainContactType = $this->getSubmittedValue('contactType');
if (!$isMainContact && $params['contact_type'] !== $mainContactType) {
// use the unsupervised dedupe rule for this contact type
$ruleId = DedupeRuleGroup::get(FALSE)
->addSelect('id')
->addWhere('contact_type', '=', $params['contact_type'])
->addWhere('used', '=', 'Unsupervised')
->execute()
->first()['id'];
}
$id = $this->getPossibleContactMatch($params, $extIDMatch, $ruleId);
if ($id && $isMainContact && $this->isSkipDuplicates()) {
throw new CRM_Core_Exception(ts('Contact matched by dedupe rule already exists in the database.'), CRM_Import_Parser::DUPLICATE);
}
Expand Down
11 changes: 10 additions & 1 deletion tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Civi\Api4\Address;
use Civi\Api4\Contact;
use Civi\Api4\ContactType;
use Civi\Api4\DedupeRuleGroup;
use Civi\Api4\Email;
use Civi\Api4\Group;
use Civi\Api4\GroupContact;
Expand Down Expand Up @@ -79,13 +80,21 @@ public function testImportParserWithEmployeeOfRelationship(): void {
$contactImportValues = [
'first_name' => 'Alok',
'last_name' => 'Patel',
'email' => 'alok@email.com',
'Employee of' => 'Agileware',
];

$values = array_values($contactImportValues);
$ruleGroupId = DedupeRuleGroup::get(FALSE)
->addSelect('id')
->addWhere('contact_type', '=', 'Individual')
->addWhere('used', '=', 'Unsupervised')
->execute()
->first()['id'];
$userJobID = $this->getUserJobID([
'mapper' => [['first_name'], ['last_name'], ['5_a_b', 'organization_name']],
'mapper' => [['first_name'], ['last_name'], ['email'], ['5_a_b', 'organization_name']],
'onDuplicate' => CRM_Import_Parser::DUPLICATE_UPDATE,
'dedupe_rule_id' => $ruleGroupId,
]);

$this->importValues($userJobID, $values, 'IMPORTED');
Expand Down

0 comments on commit 68a22a1

Please sign in to comment.