Eileen has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/373155 )
Change subject: Add ability to find duplicates for selected contacts. ...................................................................... Add ability to find duplicates for selected contacts. Notes: - This is not in my mind a final implementation. I wish to merge to core as part of extracting the code to an extension & version iteration & hence some choices may not be permanent - In the extension context the addition of the task may be by hook rather than adding to the array. I could not see any reason for the weird CONST numbering scheme in core for the task list & ignored it. - I wanted to confirm whether it is necessary to extend the task class which seems unwieldly to me & so have done this just extending CRM_Core_Form. -It occurs to me there are 2 separate actions we are interested in 1) select a bunch of contacts & find all the matches for them (based on either default rule or selecting a rule). 2) dedupe the contacts selected against each other. The patch here adds an action to contact search results (Find duplicates for these contacts) that uses the default rule to find all matches for selected contacts. This is the simpler option of those listed. Implementing 2 will require some more work on the cacheKey mechanism since we are trying to by-pass the rules. Normally I would try to focus on what I can get into core first but in this case I'm looking for a user win & to explore the code more to plan the next step upstream, which will involve refactoring. Bug: T151270 Change-Id: I2da53510e879c6260be8cee4a455d4a0a2d54693 --- A CRM/Contact/Form/Task/FindDuplicates.php M CRM/Contact/Form/Task/Merge.php M CRM/Contact/Page/AJAX.php M CRM/Contact/Page/DedupeFind.php M CRM/Contact/Task.php 5 files changed, 87 insertions(+), 5 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm/civicrm refs/changes/55/373155/1 diff --git a/CRM/Contact/Form/Task/FindDuplicates.php b/CRM/Contact/Form/Task/FindDuplicates.php new file mode 100644 index 0000000..a3c3c37 --- /dev/null +++ b/CRM/Contact/Form/Task/FindDuplicates.php @@ -0,0 +1,73 @@ +<?php +/* + +--------------------------------------------------------------------+ + | CiviCRM version 4.7 | + +--------------------------------------------------------------------+ + | Copyright CiviCRM LLC (c) 2004-2017 | + +--------------------------------------------------------------------+ + | This file is a part of CiviCRM. | + | | + | CiviCRM is free software; you can copy, modify, and distribute it | + | under the terms of the GNU Affero General Public License | + | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | + | | + | CiviCRM is distributed in the hope that it will be useful, but | + | WITHOUT ANY WARRANTY; without even the implied warranty of | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | + | See the GNU Affero General Public License for more details. | + | | + | You should have received a copy of the GNU Affero General Public | + | License and the CiviCRM Licensing Exception along | + | with this program; if not, contact CiviCRM LLC | + | at info[AT]civicrm[DOT]org. If you have questions about the | + | GNU Affero General Public License or the licensing of CiviCRM, | + | see the CiviCRM license FAQ at http://civicrm.org/licensing | + +--------------------------------------------------------------------+ + */ + +/** + * + * @package CRM + * @copyright CiviCRM LLC (c) 2004-2017 + */ + +/** + * This class provides the functionality to find potential matches. + */ +class CRM_Contact_Form_Task_FindDuplicates extends CRM_Core_Form { + + /** + * Selected contact ids. + * + * @var array + */ + public $_contactIds = array(); + + /** + * Build all the data structures needed to build the form. + */ + public function preProcess() { + CRM_Contact_Form_Task::preProcessCommon($this); + $contactType = CRM_Core_DAO::singleValueQuery( + 'SELECT GROUP_CONCAT(DISTINCT contact_type) FROM civicrm_contact WHERE id IN (' . implode($this->_contactIds). ')' + ); + + try { + $rule_group_id = civicrm_api3('RuleGroup', 'getvalue', array( + 'contact_type' => $contactType, + 'used' => 'Unsupervised', + 'return' => 'id', + 'options' => array('limit' => 1), + )); + } + catch (CiviCRM_API3_Exception $e) { + CRM_Core_Error::statusBounce(ts('It was not possible to identify a default rule that was applicable to all selected contacts. You must choose only one contact type. You chose %1', array($contactType))); + } + CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/dedupefind', array( + 'reset' => 1, + 'action' => 'update', + 'rgid' => $rule_group_id, + 'criteria' => json_encode(array('contact_id' => array('IN' => $this->_contactIds))), + ))); + } +} \ No newline at end of file diff --git a/CRM/Contact/Form/Task/Merge.php b/CRM/Contact/Form/Task/Merge.php index d0f0abd..9bbdf4e 100644 --- a/CRM/Contact/Form/Task/Merge.php +++ b/CRM/Contact/Form/Task/Merge.php @@ -33,7 +33,6 @@ /** * This class provides the functionality to Merge contacts. - * */ class CRM_Contact_Form_Task_Merge extends CRM_Contact_Form_Task { diff --git a/CRM/Contact/Page/AJAX.php b/CRM/Contact/Page/AJAX.php index cfdff39..8185937 100644 --- a/CRM/Contact/Page/AJAX.php +++ b/CRM/Contact/Page/AJAX.php @@ -649,13 +649,15 @@ $gid = CRM_Utils_Request::retrieve('gid', 'Positive'); $rgid = CRM_Utils_Request::retrieve('rgid', 'Positive'); + $null = NULL; + $criteria = json_decode(CRM_Utils_Request::retrieve('criteria', 'String', $null, FALSE, '{}'), TRUE); $selected = isset($_REQUEST['selected']) ? CRM_Utils_Type::escape($_REQUEST['selected'], 'Integer') : 0; if ($rowCount < 0) { $rowCount = 0; } $whereClause = $orderByClause = ''; - $cacheKeyString = CRM_Dedupe_Merger::getMergeCacheKeyString($rgid, $gid); + $cacheKeyString = CRM_Dedupe_Merger::getMergeCacheKeyString($rgid, $gid, $criteria); $searchRows = array(); $searchParams = self::getSearchOptionsFromRequest(); diff --git a/CRM/Contact/Page/DedupeFind.php b/CRM/Contact/Page/DedupeFind.php index 012529f..8566c7f 100644 --- a/CRM/Contact/Page/DedupeFind.php +++ b/CRM/Contact/Page/DedupeFind.php @@ -61,14 +61,17 @@ $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 0); $context = CRM_Utils_Request::retrieve('context', 'String', $this); $limit = CRM_Utils_Request::retrieve('limit', 'Integer', $this); - $rgid = CRM_Utils_Request::retrieve('rgid', 'Positive'); + $rgid = CRM_Utils_Request::retrieve('rgid', 'Positive', $this); + $criteria = CRM_Utils_Request::retrieve('criteria', 'String', $this, FALSE, '{}'); $urlQry = array( 'reset' => 1, 'rgid' => $rgid, 'gid' => $gid, 'limit' => $limit, + 'criteria' => $criteria, ); $this->assign('urlQuery', CRM_Utils_System::makeQueryString($urlQry)); + $criteria = json_decode($criteria, TRUE); if ($context == 'search') { $context = 'search'; @@ -85,7 +88,7 @@ } elseif ($action & CRM_Core_Action::MAP) { // do a batch merge if requested - $result = CRM_Dedupe_Merger::batchMerge($rgid, $gid, 'safe', 75); + $result = CRM_Dedupe_Merger::batchMerge($rgid, $gid, 'safe', 75, 2, $criteria); $skippedCount = CRM_Utils_Request::retrieve('skipped', 'Positive', $this, FALSE, 0); $skippedCount = $skippedCount + count($result['skipped']); @@ -134,7 +137,7 @@ $this->assign('sourceUrl', CRM_Utils_System::url('civicrm/ajax/dedupefind', $urlQry, FALSE, NULL, FALSE)); //reload from cache table - $cacheKeyString = CRM_Dedupe_Merger::getMergeCacheKeyString($rgid, $gid); + $cacheKeyString = CRM_Dedupe_Merger::getMergeCacheKeyString($rgid, $gid, $criteria); $stats = CRM_Dedupe_Merger::getMergeStatsMsg($cacheKeyString); if ($stats) { diff --git a/CRM/Contact/Task.php b/CRM/Contact/Task.php index 503c511..d78200d 100644 --- a/CRM/Contact/Task.php +++ b/CRM/Contact/Task.php @@ -228,6 +228,11 @@ 'class' => 'CRM_Contact_Form_Task_Merge', 'result' => TRUE, ); + self::$_tasks['find_duplicates'] = array( + 'title' => ts('Find duplicates for these contacts'), + 'class' => 'CRM_Contact_Form_Task_FindDuplicates', + 'result' => TRUE, + ); } //CRM-4418, check for delete -- To view, visit https://gerrit.wikimedia.org/r/373155 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2da53510e879c6260be8cee4a455d4a0a2d54693 Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/crm/civicrm Gerrit-Branch: master Gerrit-Owner: Eileen <emcnaugh...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits