From b2f080d5a39917be2d474ff9ddf6be06ba465d68 Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 1 Mar 2024 17:05:58 +1300 Subject: [PATCH] Pass all available relevant fields to Contact.getduplicates on checkMatchingContact I took a look at https://github.com/civicrm/civicrm-core/pull/23353 in the hopes of resolving it but it's really tricky code & there were a couple of trade offs in there I wasn't comfortable with 1) losing the faster ajax call 2) letting more worms out than absolutely necessary OTOH that patch is a bit cleverer I think in terms of not double presenting contacts. --- CRM/Contact/Form/Contact.php | 20 +++++++++++++++++++- templates/CRM/Contact/Form/Contact.tpl | 9 +-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/CRM/Contact/Form/Contact.php b/CRM/Contact/Form/Contact.php index 79f9bc5cfbf9..479835467eb5 100644 --- a/CRM/Contact/Form/Contact.php +++ b/CRM/Contact/Form/Contact.php @@ -805,7 +805,25 @@ public function buildQuickForm() { $this->assign('checkSimilar', $checkSimilar); if ($checkSimilar == 1) { $ruleParams = ['used' => 'Supervised', 'contact_type' => $this->_contactType]; - $this->assign('ruleFields', CRM_Dedupe_BAO_DedupeRule::dedupeRuleFields($ruleParams)); + // These are the fields tht are passed to apiv3 Contact.getduplicates. + // Most likely it is enough to pass only the fields returned from the function but + // this code has been a bit flip-floppy with the ruleFields removed in favour of + // the hard-coded list below here + // https://github.com/civicrm/civicrm-core/commit/01ee39a0165a6f3fdc8b105626abaa9cb951bb3f#diff-eee833728c23038f8ac3e2bbb37bef5fa1f718d327896178ae9526c31ee80672L265-R273 + // at that point the api was switched here https://github.com/civicrm/civicrm-core/commit/01ee39a0165a6f3fdc8b105626abaa9cb951bb3f#diff-eee833728c23038f8ac3e2bbb37bef5fa1f718d327896178ae9526c31ee80672R311 + // However, it was at least partially switched back here https://github.com/civicrm/civicrm-core/commit/a7ba493ce752fee7b05daa103bc1c956b7d05b0f#diff-eee833728c23038f8ac3e2bbb37bef5fa1f718d327896178ae9526c31ee80672R334 + // so deliberately erring on the side of passing too much information in hopes of breaking + // the wheel. + $ruleFields = array_unique(CRM_Dedupe_BAO_DedupeRule::dedupeRuleFields($ruleParams) + + [ + 'first_name', + 'last_name', + 'nick_name', + 'household_name', + 'organization_name', + 'email' + ]); + $this->assign('ruleFields', json_encode($ruleFields)); } // build Custom data if Custom data present in edit option diff --git a/templates/CRM/Contact/Form/Contact.tpl b/templates/CRM/Contact/Form/Contact.tpl index 631ced9484e9..8b554b26dc4f 100644 --- a/templates/CRM/Contact/Form/Contact.tpl +++ b/templates/CRM/Contact/Form/Contact.tpl @@ -244,14 +244,7 @@ {/literal}{* Ajax check for matching contacts *} {if $checkSimilar == 1} var contactType = {$contactType|@json_encode}, - rules = {*$ruleFields|@json_encode*}{literal}[ - 'first_name', - 'last_name', - 'nick_name', - 'household_name', - 'organization_name', - 'email' - ], + rules = {$ruleFields}{literal}, ruleFields = {}, $ruleElements = $(), matchMessage,