Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#1438 Enable matching on contact phone when importing contributions #16009

Merged
merged 2 commits into from
Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CRM/Dedupe/BAO/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,11 @@ public static function dedupeRuleFields($params) {
$ruleBao->find();
$ruleFields = [];
while ($ruleBao->fetch()) {
$ruleFields[] = $ruleBao->rule_field;
$field_name = $ruleBao->rule_field;
if ($field_name == 'phone_numeric') {
$field_name = 'phone';
}
$ruleFields[] = $field_name;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is perfectly fine as-is but could be replaced with just $ruleFields[] = ($ruleBao->rule_field == 'phone_numeric') ? 'phone' : $ruleBao->rule_field;. Science studies have shown using ternary operators makes other people think you are taller.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you are joking about being taller :) but I am curious about any studies of ternary operators. I find them hard to parse, whereas the code above clearly states the default (what we expect) and indicates the exception. This format also leaves room for additional exceptions to be easily added. I also know that this stuff is very subjective and I'm not sure if I'm the outlier or not!

return $ruleFields;
}
Expand Down
6 changes: 5 additions & 1 deletion CRM/Dedupe/BAO/RuleGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,11 @@ public static function dedupeRuleFieldsWeight($params) {
$ruleBao->find();
$ruleFields = [];
while ($ruleBao->fetch()) {
$ruleFields[$ruleBao->rule_field] = $ruleBao->rule_weight;
$field_name = $ruleBao->rule_field;
if ($field_name == 'phone_numeric') {
$field_name = 'phone';
}
$ruleFields[$field_name] = $ruleBao->rule_weight;
}

return [$ruleFields, $rgBao->threshold];
Expand Down
35 changes: 35 additions & 0 deletions tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,41 @@ public function testParsedCustomDates() {
$this->assertEquals('20191020000000', $formatted[$this->getCustomFieldName('date')]);
}

/**
* Test phone is included if it is part of dedupe rule.
*
* @throws \CRM_Core_Exception
*/
public function testPhoneMatchOnContact() {
// Update existing unsupervised rule, change to general.
$unsupervisedRuleGroup = $this->callApiSuccess('RuleGroup', 'getsingle', [
'used' => 'Unsupervised',
'contact_type' => 'Individual',
]);
$this->callApiSuccess('RuleGroup', 'create', [
'id' => $unsupervisedRuleGroup['id'],
'used' => 'General',
]);

// Create new unsupervised rule with Phone field.
$ruleGroup = $this->callAPISuccess('RuleGroup', 'create', [
'contact_type' => 'Individual',
'threshold' => 10,
'used' => 'Unsupervised',
'name' => 'MatchingPhone',
'title' => 'Matching Phone',
'is_reserved' => 0,
]);
$this->callAPISuccess('Rule', 'create', [
'dedupe_rule_group_id' => $ruleGroup['id'],
'rule_table' => 'civicrm_phone',
'rule_weight' => 10,
'rule_field' => 'phone_numeric',
]);
$fields = CRM_Contribute_BAO_Contribution::importableFields();
$this->assertTrue(array_key_exists('phone', $fields));
}

/**
* Run the import parser.
*
Expand Down