From: eileen Date: Mon, 28 Mar 2016 22:36:41 +0000 (+1300) Subject: CRM-18307 fix error on merge when undelete is off X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=4d834a996d59efd013c351f224b849144df832b2;p=civicrm-core.git CRM-18307 fix error on merge when undelete is off --- diff --git a/CRM/Dedupe/Merger.php b/CRM/Dedupe/Merger.php index 3483b18b9b..1e33a42f30 100644 --- a/CRM/Dedupe/Merger.php +++ b/CRM/Dedupe/Merger.php @@ -1936,13 +1936,15 @@ INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m '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', + )); + } } } diff --git a/tests/phpunit/api/v3/ContactTest.php b/tests/phpunit/api/v3/ContactTest.php index 21bf13ed4c..464a9db48f 100644 --- a/tests/phpunit/api/v3/ContactTest.php +++ b/tests/phpunit/api/v3/ContactTest.php @@ -2885,4 +2885,25 @@ class api_v3_ContactTest extends CiviUnitTestCase { } + /** + * 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)); + } + }