Skip to content

Commit

Permalink
dev/core#3879 Fix failure to accept soft credit contact id
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Nov 1, 2022
1 parent 14c5d3f commit 5c7c9e6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CRM/Contribute/Import/Parser/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ public function import(array $values): void {
$softCreditParams = [];
foreach ($params['SoftCreditContact'] ?? [] as $index => $softCreditContact) {
$softCreditParams[$index]['soft_credit_type_id'] = $softCreditContact['soft_credit_type_id'];
$softCreditParams[$index]['contact_id'] = $this->getContactID($softCreditContact['Contact'], $softCreditContact['id'] ?? NULL, 'SoftCreditContact', $this->getDedupeRulesForEntity('SoftCreditContact'));
$softCreditParams[$index]['contact_id'] = $this->getContactID($softCreditContact['Contact'], $softCreditContact['Contact']['id'] ?? NULL, 'SoftCreditContact', $this->getDedupeRulesForEntity('SoftCreditContact'));
if (empty($softCreditParams[$index]['contact_id']) && in_array($this->getActionForEntity('SoftCreditContact'), ['update', 'select'])) {
throw new CRM_Core_Exception(ts('Soft Credit Contact not found'));
}
Expand Down
38 changes: 38 additions & 0 deletions tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public function testImportParserWithSoftCreditsByExternalIdentifier(string $thou
['name' => 'financial_type_id'],
['name' => 'external_identifier'],
['name' => 'soft_credit.contact.external_identifier', 'soft_credit_type_id' => 1],
['name' => ''],
];
$this->importCSV('contributions_amount_validate.csv', $mapping, ['onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP]);

Expand All @@ -119,6 +120,27 @@ public function testImportParserWithSoftCreditsByExternalIdentifier(string $thou
$this->assertEquals(1, $dataSource->getRowCount([CRM_Import_Parser::ERROR]));
$this->assertEquals(1, $dataSource->getRowCount([CRM_Contribute_Import_Parser_Contribution::SOFT_CREDIT]));
$this->assertEquals(1, $dataSource->getRowCount([CRM_Import_Parser::VALID]));

// Now try the import with the dots swapped to double underscores. The parser
// layer and api understand the dots - but QuickForm has to play switcheroo as the dots
// break the hierarchical multiselect js. QuickForm uses a double underscore as a stand in.;
$this->validateSoftCreditImport([
['name' => 'total_amount'],
['name' => 'receive_date'],
['name' => 'financial_type_id'],
['name' => 'external_identifier'],
['name' => 'soft_credit__contact__external_identifier', 'soft_credit_type_id' => 1],
]);
$this->validateSoftCreditImport([
['name' => 'total_amount'],
['name' => 'receive_date'],
['name' => 'financial_type_id'],
['name' => 'external_identifier'],
[],
[],
[],
['name' => 'soft_credit__contact__id', 'soft_credit_type_id' => 1],
]);
}

/**
Expand Down Expand Up @@ -874,4 +896,20 @@ public function testEnableExtension(): void {
$this->assertEquals('ERROR', $result->first()['_status']);
}

/**
* @param array $mapping
*
* @throws \CRM_Core_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
protected function validateSoftCreditImport(array $mapping): void {
Contribution::delete()->addWhere('id', '>', 0)->execute();
$this->callAPISuccessGetCount('ContributionSoft', [], 0);
$this->importCSV('contributions_amount_validate.csv', $mapping, ['onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP]);
$dataSource = new CRM_Import_DataSource_CSV($this->userJobID);
// Check a row imported.
$this->assertEquals(1, $dataSource->getRowCount([CRM_Import_Parser::VALID]));
$this->callAPISuccessGetCount('ContributionSoft', [], 1);
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Total Amount,Receive Date,Financial Type,External identifier,Soft Credit Ext ID,Email,Email - soft credit
"1,230.99",2008-09-20,Donation,ext-1,ext-2,harry@example.com,the-firm@example.com
"1.230,99",2008-09-20,Donation,ext-1,ext-2,,
Total Amount,Receive Date,Financial Type,External identifier,Soft Credit Ext ID,Email,Email - soft credit,Soft credit contact ID
"1,230.99",2008-09-20,Donation,ext-1,ext-2,harry@example.com,the-firm@example.com,4
"1.230,99",2008-09-20,Donation,ext-1,ext-2,,,4

0 comments on commit 5c7c9e6

Please sign in to comment.