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

Dedupe selected fields, simplify, removed greeting id fields #29632

Merged
merged 1 commit into from
Mar 6, 2024
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
16 changes: 0 additions & 16 deletions CRM/Dedupe/BAO/DedupeRuleGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ public static function supportedFields($requestedType): array {
'civicrm_country.name' => 'civicrm_address.country_id',
'civicrm_county.name' => 'civicrm_address.county_id',
'civicrm_state_province.name' => 'civicrm_address.state_province_id',
'gender.label' => 'civicrm_contact.gender_id',
'individual_prefix.label' => 'civicrm_contact.prefix_id',
'individual_suffix.label' => 'civicrm_contact.suffix_id',
'addressee.label' => 'civicrm_contact.addressee_id',
'email_greeting.label' => 'civicrm_contact.email_greeting_id',
'postal_greeting.label' => 'civicrm_contact.postal_greeting_id',
'civicrm_phone.phone' => 'civicrm_phone.phone_numeric',
];
// the table names we support in dedupe rules - a filter for importableFields()
Expand Down Expand Up @@ -145,16 +139,6 @@ private static function importableFields($contactType): array {

$fields = CRM_Contact_DAO_Contact::import();

// get the fields thar are meant for contact types
if (in_array($contactType, [
'Individual',
'Household',
'Organization',
'All',
])) {
$fields = array_merge($fields, CRM_Core_OptionValue::getFields('', $contactType));
}

$locationFields = array_merge(CRM_Core_DAO_Address::import(),
CRM_Core_DAO_Phone::import(),
CRM_Core_DAO_Email::import(),
Expand Down
2 changes: 1 addition & 1 deletion CRM/Utils/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,7 @@ public static function dupeQuery($obj, $type, &$query) {
$null, $null, $null,
'civicrm_dupeQuery'
);
if ($original !== $query) {
if ($original !== $query && $type !== 'supportedFields') {
CRM_Core_Error::deprecatedWarning('hook_civicrm_dupeQuery is deprecated.');
}
}
Expand Down
65 changes: 51 additions & 14 deletions tests/phpunit/CRM/Dedupe/BAO/RuleGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class CRM_Dedupe_BAO_RuleGroupTest extends CiviUnitTestCase {
*
* @var array
*/
protected $contactIDs = [];
protected array $contactIDs = [];

/**
* ID of the group holding the contacts.
Expand Down Expand Up @@ -103,9 +103,12 @@ public function tearDown(): void {
*
* This is a statically maintained (in this test list).
*
* @param string $contactType
*
* @return array
*/
public function getSupportedFields() {
return [
public function getSupportedFields(string $contactType): array {
$sharedFields = [
'civicrm_address' =>
[
'name' => 'Address Name',
Expand All @@ -125,7 +128,6 @@ public function getSupportedFields() {
],
'civicrm_contact' =>
[
'addressee_id' => 'Addressee',
'addressee_custom' => 'Addressee Custom',
'id' => 'Contact ID',
'source' => 'Contact Source',
Expand All @@ -135,20 +137,15 @@ public function getSupportedFields() {
'do_not_phone' => 'Do Not Phone',
'do_not_sms' => 'Do Not Sms',
'do_not_trade' => 'Do Not Trade',
'email_greeting_id' => 'Email Greeting',
'email_greeting_custom' => 'Email Greeting Custom',
'external_identifier' => 'External Identifier',
'image_URL' => 'Image Url',
'legal_identifier' => 'Legal Identifier',
'legal_name' => 'Legal Name',
'nick_name' => 'Nickname',
'is_opt_out' => 'No Bulk Emails (User Opt Out)',
'organization_name' => 'Organization Name',
'postal_greeting_id' => 'Postal Greeting',
'postal_greeting_custom' => 'Postal Greeting Custom',
'preferred_communication_method' => 'Preferred Communication Method',
'preferred_language' => 'Preferred Language',
'sic_code' => 'Sic Code',
'user_unique_id' => 'Unique ID (OpenID)',
'sort_name' => 'Sort Name',
'communication_style_id' => 'Communication Style',
Expand Down Expand Up @@ -181,6 +178,31 @@ public function getSupportedFields() {
'url' => 'Website',
],
];
$contactTypeFields = [
'Organization' => [
'legal_name' => 'Legal Name',
'organization_name' => 'Organization Name',
'sic_code' => 'Sic Code',
],
'Individual' => [
'birth_date' => 'Birth Date',
'is_deceased' => 'Deceased',
'deceased_date' => 'Deceased Date',
'first_name' => 'First Name',
'formal_title' => 'Formal Title',
'gender_id' => 'Gender ID',
'prefix_id' => 'Individual Prefix',
'suffix_id' => 'Individual Suffix',
'job_title' => 'Job Title',
'last_name' => 'Last Name',
'middle_name' => 'Middle Name',
],
'Household' => [
'household_name' => 'Household Name',
],
];
Comment on lines +181 to +203
Copy link
Member

Choose a reason for hiding this comment

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

This metadata already exists in DAO_Contact::getFields(). E.g. the household_name field has this:

'contactType' => 'Household',

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@colemanw yeah - but the point of hard-coding it in the test is to make sure it doesn't change at all & this is a static reference to id

Copy link
Member

Choose a reason for hiding this comment

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

Ok sure. As long as the live code is reading from the metadata. Is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@colemanw yep - the live code is readying from DAO::import() but I want to switch it to reading from the api

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@colemanw the live code also does this #29631 - which is fortunately tested so I plan to deconstruct that

$sharedFields['civicrm_contact'] += $contactTypeFields[$contactType];
return $sharedFields;
}

/**
Expand All @@ -197,8 +219,23 @@ public function getSupportedFields() {
*/
public function testSupportedFields(): void {
$fields = CRM_Dedupe_BAO_DedupeRuleGroup::supportedFields('Organization');
$this->assertEquals($this->getSupportedFields('Organization'), $fields);
}

/**
* Test individual supported fields.
*/
public function testSupportedFieldsIndividual(): void {
$fields = CRM_Dedupe_BAO_DedupeRuleGroup::supportedFields('Individual');
$this->assertEquals($this->getSupportedFields('Individual'), $fields);
}

$this->assertEquals($this->getSupportedFields(), $fields);
/**
* Test individual supported fields.
*/
public function testSupportedFieldsHousehold(): void {
$fields = CRM_Dedupe_BAO_DedupeRuleGroup::supportedFields('Household');
$this->assertEquals($this->getSupportedFields('Household'), $fields);
}

/**
Expand All @@ -210,10 +247,10 @@ public function testSupportedCustomFields(): void {
$customGroup = $this->createCustomGroup(['extends' => 'Organization']);

$customGroupID = $this->ids['CustomGroup']['Custom Group'];
$cf = $this->createTextCustomField(['custom_group_id' => $customGroupID]);
$customField = $this->createTextCustomField(['custom_group_id' => $customGroupID]);

$fields = $this->getSupportedFields();
$fields[$this->getCustomGroupTable()][$cf['column_name']] = 'Custom Group' . ' : ' . $cf['label'];
$fields = $this->getSupportedFields('Organization');
$fields[$this->getCustomGroupTable()][$customField['column_name']] = 'Custom Group' . ' : ' . $customField['label'];

$this->assertEquals($fields, CRM_Dedupe_BAO_DedupeRuleGroup::supportedFields('Organization'));
}
Expand All @@ -234,7 +271,7 @@ public function testSupportedCustomFieldsSubtype(): void {
$customGroupID = $this->ids['CustomGroup']['Custom Group'];
$cf = $this->createTextCustomField(['custom_group_id' => $customGroupID]);

$fields = $this->getSupportedFields();
$fields = $this->getSupportedFields('Organization');
$fields[$this->getCustomGroupTable()][$cf['column_name']] = 'Custom Group' . ' : ' . $cf['label'];

$this->assertEquals($fields, CRM_Dedupe_BAO_DedupeRuleGroup::supportedFields('Organization'));
Expand Down