Eileen has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/382112 )
Change subject: Numbers are not people
......................................................................
Numbers are not people
Bug: T175747
Change-Id: Ia7642c08af3bb977b5542fbb9f696b46f35b4891
---
M sites/all/modules/wmf_civicrm/tests/phpunit/MergeTest.php
M sites/all/modules/wmf_civicrm/wmf_civicrm.module
2 files changed, 61 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm
refs/changes/12/382112/1
diff --git a/sites/all/modules/wmf_civicrm/tests/phpunit/MergeTest.php
b/sites/all/modules/wmf_civicrm/tests/phpunit/MergeTest.php
index b751200..442ab18 100644
--- a/sites/all/modules/wmf_civicrm/tests/phpunit/MergeTest.php
+++ b/sites/all/modules/wmf_civicrm/tests/phpunit/MergeTest.php
@@ -526,6 +526,20 @@
}
/**
+ * Test that we ignore numbers as names.
+ *
+ * Bug T175747
+ */
+ public function testBatchMergeResolvableConflictNumbersAreNotPeople() {
+ $this->breedDuck(array('id' => $this->contactID, 'first_name' => 'alter.
ego'));
+ $this->breedDuck(array('id' => $this->contactID2, 'first_name' => '1'));
+ $result = $this->callAPISuccess('Job', 'process_batch_merge', array('mode'
=> 'safe'));
+ $this->assertEquals(1, count($result['values']['merged']));
+ $contact = $this->callAPISuccessGetSingle('Contact', array('email' =>
'[email protected]'));
+ $this->assertEquals('alter. ego', $contact['first_name']);
+ }
+
+ /**
* Test that a conflict on casing in first names is handled.
*
* We do a best effort on this to get the more correct on assuming that 1
capital letter in a
diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
index a475b04..bd4dc51 100644
--- a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
+++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
@@ -2471,6 +2471,15 @@
return;
}
+ if (_wmf_civicrm_merge_resolve_inappropriate_data_conflict(
+ $dbFieldName,
+ $refs['migration_info'][$moveField],
+ $refs['migration_info']['rows'][$moveField]['other'],
+ $refs['migration_info']['rows'][$moveField]['main'])) {
+ unset($refs['fields_in_conflict'][$moveField]);
+ return;
+ }
+
if (substr($moveField, 0, 13) === 'move_location') {
if (!isset($refs['is_major_gift'])) {
$refs['is_major_gift'] =
_wmf_civicrm_is_merged_contact_major_donor($mainId, $otherId);
@@ -2671,6 +2680,44 @@
}
/**
+ * Resolve conflicts whether the data is not appropriate to the field.
+ *
+ * A numeric name is not valid so if we have a non-numeric alternative we
+ * should take it.
+ *
+ * @param string $fieldName
+ * @param string $moveFieldValue
+ * @param string $valueToKeep
+ * @param string $valueToOverwrite
+ *
+ * @return bool
+ */
+function _wmf_civicrm_merge_resolve_inappropriate_data_conflict($fieldName,
&$moveFieldValue, &$valueToKeep, &$valueToOverwrite) {
+ $fieldsToResolve = array('last_name', 'first_name');
+ if (!in_array(str_replace('move_', '', $fieldName), $fieldsToResolve)) {
+ return FALSE;
+ }
+ // Let's get rid of any preceding or trailing spaces.
+ $valueToKeep = trim($valueToKeep);
+ $valueToOverwrite = trim($valueToOverwrite);
+ $moveFieldValue = trim($moveFieldValue);
+
+ if (!is_numeric($valueToKeep) && !is_numeric($valueToOverwrite)) {
+ return FALSE;
+ }
+
+ if (is_numeric($valueToOverwrite)) {
+ // We are already overwriting the number so individualism is winning.
+ return TRUE;
+ }
+ // We have a conflict to resolve and we are going to resolve it by keeping
+ //the value that was to be overwritten.
+ $moveFieldValue = $valueToOverwrite;
+ $valueToKeep = $valueToOverwrite;
+ return TRUE;
+}
+
+/**
* Check for special characters (none latin) in the string.
*
* @param string $string
--
To view, visit https://gerrit.wikimedia.org/r/382112
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia7642c08af3bb977b5542fbb9f696b46f35b4891
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Eileen <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits