])->execute()->first();
$campaignParams = isset($params['campaign_id']) ? ['campaign_id' => ($params['campaign_id'] ?? NULL)] : [];
- Activity::save(FALSE)->addRecord(array_merge([
+ $activityParams = array_merge([
'activity_type_id:name' => 'Contribution',
'source_record_id' => $contribution->id,
- 'source_contact_id' => CRM_Core_Session::getLoggedInContactID() ?: $contribution->contact_id,
- 'target_contact_id' => CRM_Core_Session::getLoggedInContactID() ? [$contribution->contact_id] : [],
'activity_date_time' => $contribution->receive_date,
'is_test' => (bool) $contribution->is_test,
'status_id:name' => $isCompleted ? 'Completed' : 'Scheduled',
'skipRecentView' => TRUE,
'subject' => CRM_Activity_BAO_Activity::getActivitySubject($contribution),
'id' => $existingActivity['id'] ?? NULL,
- ], $campaignParams))->execute();
+ ], $campaignParams);
+ if (!$activityParams['id']) {
+ // Don't set target contacts on update as these will have been
+ // correctly created and we risk overwriting them with
+ // 'best guess' params.
+ $activityParams['source_contact_id'] = (int) ($params['source_contact_id'] ?? (CRM_Core_Session::getLoggedInContactID() ?: $contribution->contact_id));
+ $activityParams['target_contact_id'] = ($activityParams['source_contact_id'] === (int) $contribution->contact_id) ? [] : [$contribution->contact_id];
+ }
+ Activity::save(FALSE)->addRecord($activityParams)->execute();
}
// do not add to recent items for import, CRM-4399
}
/**
- * Test submitted the search form.
+ * Test submitted the search form.
+ *
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
- public function testSearch() {
+ public function testSearch(): void {
$form = new CRM_Activity_Form_Search();
$_SERVER['REQUEST_METHOD'] = 'GET';
* Note the group combinations & expected results:
*
* @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
- public function testBatchMergeWithAssets() {
+ public function testBatchMergeWithAssets(): void {
$contactID = $this->individualCreate();
$contact2ID = $this->individualCreate();
$this->contributionCreate(['contact_id' => $contactID]);