-
-
Notifications
You must be signed in to change notification settings - Fork 824
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#5433 Add legacydedupefinder #31689
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,13 @@ | |
* The CiviCRM duplicate discovery engine is based on an | ||
* algorithm designed by David Strauss <[email protected]>. | ||
*/ | ||
class CRM_Dedupe_BAO_DedupeRuleGroup extends CRM_Dedupe_DAO_DedupeRuleGroup { | ||
class CRM_Dedupe_BAO_DedupeRuleGroup extends CRM_Dedupe_DAO_DedupeRuleGroup implements \Symfony\Component\EventDispatcher\EventSubscriberInterface { | ||
|
||
public static function getSubscribedEvents(): array { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be needed one switched to using the hookInterface There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how do you specify weight with hook interface? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right @eileenmcnaughton if you want to specify priority level you need to use |
||
return [ | ||
'hook_civicrm_findExistingDuplicates' => ['hook_civicrm_findExistingDuplicates', -20], | ||
]; | ||
} | ||
|
||
/** | ||
* @var array | ||
|
@@ -131,6 +137,36 @@ public function tableDropQuery() { | |
return 'DROP TEMPORARY TABLE IF EXISTS dedupe'; | ||
} | ||
|
||
/** | ||
* Find existing duplicates in the database for the given rule and limitations. | ||
* | ||
* @return void | ||
*/ | ||
public static function hook_civicrm_findExistingDuplicates(\Civi\Core\Event\GenericHookEvent $event) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should change to self_hook_civicrm_findExistingDuplicates as per https://github.com/civicrm/civicrm-core/blob/master/CRM/Core/BAO/OptionGroup.php#L83 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think what @eileenmcnaughton did is correct. Since she needs to specify priority this is the way to do it. |
||
$ruleGroupIDs = $event->ruleGroupIDs; | ||
$ruleGroup = new \CRM_Dedupe_BAO_DedupeRuleGroup(); | ||
$ruleGroup->id = reset($ruleGroupIDs); | ||
$contactIDs = []; | ||
$whereClauses = $event->whereClauses; | ||
if (!empty($whereClauses)) { | ||
foreach ($whereClauses as $whereClause) { | ||
if ($whereClause[0] === 'id' && $whereClause[1] === 'IN') { | ||
$contactIDs = $whereClause[2]; | ||
} | ||
} | ||
} | ||
if (!$ruleGroup->fillTable($ruleGroup->id, $contactIDs, [], FALSE)) { | ||
return; | ||
} | ||
$dao = \CRM_Core_DAO::executeQuery($ruleGroup->thresholdQuery($event->checkPermissions)); | ||
$duplicates = []; | ||
while ($dao->fetch()) { | ||
$duplicates[] = ['entity_id_1' => $dao->id1, 'entity_id_2' => $dao->id2, 'weight' => $dao->weight]; | ||
} | ||
$event->duplicates = $duplicates; | ||
\CRM_Core_DAO::executeQuery($ruleGroup->tableDropQuery()); | ||
} | ||
|
||
/** | ||
* Fill the dedupe finder table. | ||
* | ||
|
@@ -139,32 +175,41 @@ public function tableDropQuery() { | |
* @param int $id | ||
* @param array $contactIDs | ||
* @param array $params | ||
* @param bool $legacyMode | ||
* Legacy mode is called to give backward hook compatibility, in the legacydedupefinder | ||
* extension. It is intended to be transitional, with the non-legacy mode being | ||
* separated out and optimized once it no longer has to comply with the legacy | ||
* hook and reserved query methodology. | ||
* | ||
* @return bool | ||
* @throws \Civi\Core\Exception\DBQueryException | ||
*/ | ||
public function fillTable(int $id, array $contactIDs, array $params): bool { | ||
$this->contactIds = $contactIDs; | ||
$this->params = $params; | ||
public function fillTable(int $id, array $contactIDs, array $params, $legacyMode = TRUE): bool { | ||
if ($legacyMode) { | ||
$this->contactIds = $contactIDs; | ||
$this->params = $params; | ||
} | ||
$this->id = $id; | ||
// make sure we've got a fetched dbrecord, not sure if this is enforced | ||
$this->find(TRUE); | ||
$optimizer = new CRM_Dedupe_FinderQueryOptimizer($this->id, $contactIDs, $params); | ||
// Reserved Rule Groups can optionally get special treatment by | ||
// implementing an optimization class and returning a query array. | ||
if ($optimizer->isUseReservedQuery()) { | ||
if ($legacyMode && $optimizer->isUseReservedQuery()) { | ||
$tableQueries = $optimizer->getReservedQuery(); | ||
} | ||
else { | ||
$tableQueries = $optimizer->getRuleQueries(); | ||
} | ||
// if there are no rules in this rule group | ||
// add an empty query fulfilling the pattern | ||
if (!$tableQueries) { | ||
// Just for the hook.... (which is deprecated). | ||
$this->noRules = TRUE; | ||
if ($legacyMode) { | ||
if (!$tableQueries) { | ||
// Just for the hook.... (which is deprecated). | ||
$this->noRules = TRUE; | ||
} | ||
CRM_Utils_Hook::dupeQuery($this, 'table', $tableQueries); | ||
} | ||
CRM_Utils_Hook::dupeQuery($this, 'table', $tableQueries); | ||
if (empty($tableQueries)) { | ||
return FALSE; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Civi\LegacyFinder; | ||
|
||
use Civi\Core\Event\GenericHookEvent; | ||
|
||
class Finder { | ||
|
||
/** | ||
* This function exists to provide legacy hook support for finding duplicates. | ||
* | ||
* @return void | ||
*/ | ||
public static function findExistingDuplicates(GenericHookEvent $event) { | ||
$event->stopPropagation(); | ||
$ruleGroupIDs = $event->ruleGroupIDs; | ||
$ruleGroup = new \CRM_Dedupe_BAO_DedupeRuleGroup(); | ||
$ruleGroup->id = reset($ruleGroupIDs); | ||
$contactIDs = []; | ||
$whereClauses = $event->whereClauses; | ||
if (!empty($whereClauses)) { | ||
foreach ($whereClauses as $whereClause) { | ||
if ($whereClause[0] === 'id' && $whereClause[1] === 'IN') { | ||
$contactIDs = $whereClause[2]; | ||
} | ||
} | ||
} | ||
if (!$ruleGroup->fillTable($ruleGroup->id, $contactIDs, [])) { | ||
return; | ||
} | ||
$dao = \CRM_Core_DAO::executeQuery($ruleGroup->thresholdQuery($event->checkPermissions)); | ||
$duplicates = []; | ||
while ($dao->fetch()) { | ||
$duplicates[] = ['entity_id_1' => $dao->id1, 'entity_id_2' => $dao->id2, 'weight' => $dao->weight]; | ||
} | ||
$event->duplicates = $duplicates; | ||
\CRM_Core_DAO::executeQuery($ruleGroup->tableDropQuery()); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eileenmcnaughton this should be the \Civi\Core\HookInterface not Event Subscriber Interface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seamuslee001 I didn't really figure out which is which based on the docs - but this one seems to allow me to specify the weight