Import contribution fails if using soft-credit and a row has an empty field
To reproduce:
- use this CSV file: test-soft-credit.csv
- on dmaster, Contributions > Import
- upload the CSV file, leave the rest as-it
- in field mappings, make sure to select the Soft-Credit ID:
Then run the import, it will be stuck like this:
Fatal error:
Argument 2 passed to CRM_Import_Parser::getContactID() must be of the type int or null, string given, called in
CRM/Contribute/Import/Parser/Contribution.php on line 443 in CRM_Import_Parser->getContactID()
(line 2321 of CRM/Import/Parser.php).
I worked around it by adding an "if not empty" clause around that code:
$softCreditParams = [];
foreach ($params['SoftCreditContact'] ?? [] as $index => $softCreditContact) {
if (!empty($softCreditContact['Contact']['id'])) {
$softCreditParams[$index]['soft_credit_type_id'] = $softCreditContact['soft_credit_type_id'];
$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'));
}
}
}
but this looks a bit fishy to me.