CRM-18307 fix error on merge when undelete is off
authoreileen <emcnaughton@wikimedia.org>
Mon, 28 Mar 2016 22:36:41 +0000 (11:36 +1300)
committereileen <emcnaughton@wikimedia.org>
Mon, 28 Mar 2016 22:43:07 +0000 (11:43 +1300)
CRM/Dedupe/Merger.php
tests/phpunit/api/v3/ContactTest.php

index 3483b18b9bc932420cd533cba99f56aeae2fd263..1e33a42f30acdb1e5f57776b1e10e201a412482e 100644 (file)
@@ -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',
+      ));
+    }
   }
 
 }
index 21bf13ed4c2e70365ea3019a26ee0ca8b4a06e96..464a9db48f26fc44106bf172bdf8bcc1c5544a9f 100644 (file)
@@ -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));
+  }
+
 }