// Rule: If both main-contact, and other-contact have a field with a
// different value, then let $mode decide if to merge it or not
if (
- !empty($migrationInfo['rows'][$key]['main'])
+ (!empty($migrationInfo['rows'][$key]['main'])
+ // For custom fields a 0 (e.g in an int field) could be a true conflict. This
+ // is probably true for other fields too - e.g. 'do_not_email' but
+ // leaving that investigation as a @todo - until tests can be written.
+ // Note the handling of this has test coverage - although the data-typing
+ // of '0' feels flakey we have insurance.
+ || ($migrationInfo['rows'][$key]['main'] === '0' && substr($key, 0, 12) == 'move_custom_')
+ )
&& $migrationInfo['rows'][$key]['main'] != $migrationInfo['rows'][$key]['other']
) {
$this->assertEquals('2012-11-03 00:00:00', $contact[$customFieldLabel]);
}
+ /**
+ * Check we get a no conflict on the custom field & integer merges.
+ */
+ public function testBatchMergeIntCustomFieldNoConflict() {
+ $customGroup = $this->customGroupCreate();
+ $this->customGroupID = $customGroup['id'];
+ $customField = $this->customFieldCreate(array(
+ 'custom_group_id' => $this->customGroupID,
+ 'data_type' => 'Integer',
+ 'html_type' => 'Text',
+ 'default_value' => '',
+ ));
+ $this->customFieldID = $customField['id'];
+ $customFieldLabel = 'custom_' . $this->customFieldID;
+ $contactID = $this->individualCreate(array());
+ $this->individualCreate(array($customFieldLabel => 20));
+ $result = $this->callAPISuccess('Job', 'process_batch_merge', array());
+ $this->assertEquals(1, count($result['values']['merged']));
+ $this->assertEquals(0, count($result['values']['skipped']));
+ $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel));
+ $this->assertEquals(20, $contact[$customFieldLabel]);
+ }
+
+ /**
+ * Check we get a conflict on the integer custom field.
+ */
+ public function testBatchMergeIntCustomFieldConflict() {
+ $customGroup = $this->customGroupCreate();
+ $this->customGroupID = $customGroup['id'];
+ $customField = $this->customFieldCreate(array(
+ 'custom_group_id' => $this->customGroupID,
+ 'data_type' => 'Integer',
+ 'html_type' => 'Text',
+ 'default_value' => '',
+ ));
+ $this->customFieldID = $customField['id'];
+ $customFieldLabel = 'custom_' . $this->customFieldID;
+ $contactID = $this->individualCreate(array($customFieldLabel => 20));
+ $this->individualCreate(array($customFieldLabel => 1));
+ $result = $this->callAPISuccess('Job', 'process_batch_merge', array());
+ $this->assertEquals(0, count($result['values']['merged']));
+ $this->assertEquals(1, count($result['values']['skipped']));
+ $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel));
+ $this->assertEquals(20, $contact[$customFieldLabel]);
+ }
+
+ /**
+ * Check we get a conflict on the integer custom field when the conflicted field is 0.
+ */
+ public function testBatchMergeIntCustomFieldConflictZero() {
+ $customGroup = $this->customGroupCreate();
+ $this->customGroupID = $customGroup['id'];
+ $customField = $this->customFieldCreate(array(
+ 'custom_group_id' => $this->customGroupID,
+ 'data_type' => 'Integer',
+ 'html_type' => 'Text',
+ 'default_value' => '',
+ ));
+ $this->customFieldID = $customField['id'];
+ $customFieldLabel = 'custom_' . $this->customFieldID;
+ $contactID = $this->individualCreate(array($customFieldLabel => 0));
+ $this->individualCreate(array($customFieldLabel => 20));
+ $result = $this->callAPISuccess('Job', 'process_batch_merge', array());
+ $this->assertEquals(0, count($result['values']['merged']));
+ $this->assertEquals(1, count($result['values']['skipped']));
+ $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel));
+ $this->assertEquals(0, $contact[$customFieldLabel]);
+ }
+
/**
* Using the api with check perms set to off, make sure custom data is merged.git
*