$paramValues['contact_type'] = $this->getContactType();
}
elseif ($this->isUpdateExisting() &&
- (!empty($paramValues['contribution_id']) || !empty($values['trxn_id']) || !empty($paramValues['invoice_id']))
+ (!empty($paramValues['id']) || !empty($values['trxn_id']) || !empty($paramValues['invoice_id']))
) {
$paramValues['contact_type'] = $this->getContactType();
}
if ($this->isUpdateExisting()) {
//fix for CRM-2219 - Update Contribution
// onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE
- if (!empty($paramValues['invoice_id']) || !empty($paramValues['trxn_id']) || !empty($paramValues['contribution_id'])) {
+ if (!empty($paramValues['invoice_id']) || !empty($paramValues['trxn_id']) || !empty($paramValues['id'])) {
$dupeIds = [
- 'id' => $paramValues['contribution_id'] ?? NULL,
+ 'id' => $paramValues['id'] ?? NULL,
'trxn_id' => $paramValues['trxn_id'] ?? NULL,
'invoice_id' => $paramValues['invoice_id'] ?? NULL,
];
$params['contribution_contact_id'] = $matchingContactIds[0];
}
}
- elseif (!empty($params['contribution_id']) || !empty($params['trxn_id']) || !empty($params['invoice_id'])) {
+ elseif (!empty($params['id']) || !empty($params['trxn_id']) || !empty($params['invoice_id'])) {
// when update mode check contribution id or trxn id or
// invoice id
+ // @todo - this check is obsolete. It survives for now
+ // in order to keep the rc patch small & non-conflicty.
$contactId = new CRM_Contribute_DAO_Contribution();
- if (!empty($params['contribution_id'])) {
- $contactId->id = $params['contribution_id'];
+ if (!empty($params['id'])) {
+ $contactId->id = $params['id'];
}
elseif (!empty($params['trxn_id'])) {
$contactId->trxn_id = $params['trxn_id'];
$this->assertEquals('No matching Contact found for (mum@example.com )', $row['_status_message']);
}
+ /**
+ * @throws \CRM_Core_Exception
+ */
public function testImportWithMatchByExternalIdentifier() :void {
CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_contact AUTO_INCREMENT = 1000000");
return $userJobID;
}
+ /**
+ * Test that existing contributions are found and updated.
+ *
+ * @throws \CRM_Core_Exception
+ */
+ public function testImportUpdateExisting(): void {
+ $this->contributionCreate([
+ 'contact_id' => $this->individualCreate(),
+ 'trxn_id' => 'abc',
+ 'invoice_id' => '65',
+ 'total_amount' => 8,
+ 'financial_type_id:name' => 'Event Fee',
+ ]);
+ $mapping = [
+ ['name' => 'contribution_id'],
+ ['name' => 'invoice_id'],
+ ['name' => 'trxn_id'],
+ ['name' => ''],
+ ['name' => 'total_amount'],
+ ['name' => 'receive_date'],
+ ['name' => 'financial_type_id'],
+ ['name' => 'contribution_source'],
+ ['name' => ''],
+ ];
+ $this->importCSV('contributions_update.csv', $mapping, ['onDuplicate' => CRM_Import_Parser::DUPLICATE_UPDATE]);
+ $rows = $this->getDataSource()->getRows();
+ foreach ($rows as $row) {
+ if ($row[8] === 'valid') {
+ // Note that as the valid value is 'IMPORTED' - but the fix to make that correct
+ // is not in 5.53 so temporary support for pledge_payment_imported
+ $this->assertContains($row[10], ['pledge_payment_imported', 'IMPORTED'], $row[11]);
+ }
+ else {
+ $this->assertEquals('ERROR', $row[10], $row[11]);
+ }
+ }
+ }
+
/**
* Add a random extra option value
*
--- /dev/null
+Contribution ID,Invoice ID,Trxn ID,Contact ID,Total Amount,Receive Date,Financial Type,Reason,Row Status
+1,67,abc,8,999,2008-09-20,Donation,Invoice ID mismatch,invalid
+1,67,abcd,8,999,2008-09-20,Donation,Trxn ID mismatch,invalid
+1,65,abc,3,999,2008-09-20,Donation,All fields OK,valid
+,65,abc,3,999,2008-09-20,Donation,Only Invoice ID OK,valid
+1,,"",3,99,2008-09-20,Donation,Only Contribution ID OK,valid
+