'activity_type_id' => 'Contact Merged',
'status_id' => 'Completed',
));
- civicrm_api3('activity', 'create', array(
- 'subject' => ts('Contact ID %1 has been merged into Contact ID %2 and deleted.', $params),
- 'target_contact_id' => $otherId,
- 'activity_type_id' => 'Contact Deleted by Merge',
- 'parent_id' => $activity['id'],
- 'status_id' => 'Completed',
- ));
+ if (civicrm_api3('Setting', 'getvalue', array('name' => 'contact_undelete', 'group' => 'CiviCRM Preferences'))) {
+ civicrm_api3('activity', 'create', array(
+ 'subject' => ts('Contact ID %1 has been merged into Contact ID %2 and deleted.', $params),
+ 'target_contact_id' => $otherId,
+ 'activity_type_id' => 'Contact Deleted by Merge',
+ 'parent_id' => $activity['id'],
+ 'status_id' => 'Completed',
+ ));
+ }
}
}
}
+ /**
+ * Test merging 2 contacts with delete to trash off.
+ *
+ * We are checking that there is no error due to attempting to add an activity for the
+ * deleted contact.
+ *
+ * CRM-18307
+ */
+ public function testMergeNoTrash() {
+ $this->createLoggedInUser();
+ $this->callAPISuccess('Setting', 'create', array('contact_undelete' => FALSE));
+ $otherContact = $this->callAPISuccess('contact', 'create', $this->_params);
+ $retainedContact = $this->callAPISuccess('contact', 'create', $this->_params);
+ $this->callAPISuccess('contact', 'merge', array(
+ 'to_keep_id' => $retainedContact['id'],
+ 'to_remove_id' => $otherContact['id'],
+ 'auto_flip' => FALSE,
+ ));
+ $this->callAPISuccess('Setting', 'create', array('contact_undelete' => TRUE));
+ }
+
}