*/
public static function skipMerge($mainId, $otherId, &$migrationInfo, $mode = 'safe', &$conflicts = array()) {
- $migrationData = array(
- 'old_migration_info' => $migrationInfo,
- 'mode' => $mode,
- );
-
+ $originalMigrationInfo = $migrationInfo;
foreach ($migrationInfo as $key => $val) {
if ($val === "null") {
// Rule: Never overwrite with an empty value (in any mode)
// there's a conflict (to handle "gotchas"). fields_in_conflict could be modified here
// merge happens with new values filled in here. For a particular field / row not to be merged
// field should be unset from fields_in_conflict.
- $migrationData['fields_in_conflict'] = $conflicts;
- $migrationData['merge_mode'] = $mode;
+ $migrationData = array(
+ 'old_migration_info' => $originalMigrationInfo,
+ 'mode' => $mode,
+ 'fields_in_conflict' => $conflicts,
+ 'merge_mode' => $mode,
+ 'migration_info' => $migrationInfo,
+ );
CRM_Utils_Hook::merge('batch', $migrationData, $mainId, $otherId);
$conflicts = $migrationData['fields_in_conflict'];
// allow hook to override / manipulate migrationInfo as well
- $migrationInfo = $migrationData['old_migration_info'];
+ $migrationInfo = $migrationData['migration_info'];
if (!empty($conflicts)) {
foreach ($conflicts as $key => $val) {
}
/**
- * Test that in aggressive mode our conflicted contacts are merged.
+ * Test the batch merge does not create duplicate emails.
+ *
+ * Test CRM-18546, a 4.7 regression whereby a merged contact gets duplicate emails.
*/
- public function testBatchMergeAggressive() {
-
+ public function testBatchMergeEmailHandling() {
+ for ($x = 0; $x <= 4; $x++) {
+ $id = $this->individualCreate(array('email' => 'batman@gotham.met'));
+ }
+ $result = $this->callAPISuccess('Job', 'process_batch_merge', array());
+ $this->assertEquals(4, count($result['values']['merged']));
+ $this->callAPISuccessGetCount('Contact', array('email' => 'batman@gotham.met'), 1);
+ $contacts = $this->callAPISuccess('Contact', 'get', array('is_deleted' => 0));
+ $deletedContacts = $this->callAPISuccess('Contact', 'get', array('is_deleted' => 1));
+ $this->callAPISuccessGetCount('Email', array(
+ 'email' => 'batman@gotham.met',
+ 'contact_id' => array('IN' => array_keys($contacts['values'])),
+ ), 1);
+ $this->callAPISuccessGetCount('Email', array(
+ 'email' => 'batman@gotham.met',
+ 'contact_id' => array('IN' => array_keys($deletedContacts['values'])),
+ ), 4);
}
/**