3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Contact_Page_DedupeFind
extends CRM_Core_Page_Basic
{
18 protected $_cid = NULL;
20 protected $_mainContacts;
24 * Only display selected.
31 * Get isSelected value.
33 * This needs to be an integer of 0 or 1 or NULL for no filter.
37 public function isSelected() {
38 return ($this->selected
=== NULL) ?
NULL : (int) $this->selected
;
47 public function getBAOName() {
48 return 'CRM_Dedupe_BAO_RuleGroup';
54 public function &links() {
58 * Initialize properties from input.
60 protected function initialize() {
61 $this->selected
= CRM_Utils_Request
::retrieveValue('selected', 'Boolean');
65 * Browse all rule groups.
67 public function run() {
69 $gid = CRM_Utils_Request
::retrieve('gid', 'Positive', $this, FALSE, 0);
70 $action = CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 0);
71 $context = CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this);
72 $limit = CRM_Utils_Request
::retrieve('limit', 'Integer', $this);
73 $rgid = CRM_Utils_Request
::retrieve('rgid', 'Positive', $this);
74 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this, FALSE, 0);
76 $criteria = CRM_Utils_Request
::retrieve('criteria', 'Json', $this, FALSE, '{}');
77 $this->assign('criteria', $criteria);
79 $isConflictMode = ($context == 'conflicts');
92 'limit' => (int) $limit,
93 'criteria' => $criteria,
95 $this->assign('urlQuery', CRM_Utils_System
::makeQueryString($urlQry));
96 $this->assign('isSelected', $this->isSelected());
97 $criteria = json_decode($criteria, TRUE);
98 $cacheKeyString = CRM_Dedupe_Merger
::getMergeCacheKeyString($rgid, $gid, $criteria, TRUE, $limit);
99 $this->assign('cacheKey', $cacheKeyString);
101 if ($context == 'search') {
103 $this->assign('backURL', CRM_Core_Session
::singleton()->readUserContext());
106 if ($action & CRM_Core_Action
::RENEW
) {
109 CRM_Core_BAO_PrevNextCache
::deleteItem(NULL, $cacheKeyString);
111 $urlQry['action'] = 'update';
112 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contact/dedupefind', $urlQry));
114 elseif ($action & CRM_Core_Action
::MAP
) {
115 // do a batch merge if requested
116 $result = CRM_Dedupe_Merger
::batchMerge($rgid, $gid, 'safe', 75, 2, $criteria, TRUE, NULL, $limit);
118 $skippedCount = CRM_Utils_Request
::retrieve('skipped', 'Positive', $this, FALSE, 0);
119 $skippedCount = $skippedCount +
count($result['skipped']);
120 $mergedCount = CRM_Utils_Request
::retrieve('merged', 'Positive', $this, FALSE, 0);
121 $mergedCount = $mergedCount +
count($result['merged']);
123 if (empty($result['merged']) && empty($result['skipped'])) {
125 if ($mergedCount >= 1) {
126 $message = ts("%1 pairs of duplicates were merged", [1 => $mergedCount]);
128 if ($skippedCount >= 1) {
129 $message = $message ?
"{$message} and " : '';
130 $message .= ts("%1 pairs of duplicates were skipped due to conflict",
134 $message .= ts(" during the batch merge process with safe mode.");
135 CRM_Core_Session
::setStatus($message, ts('Merge Complete'), 'success');
136 $urlQry['action'] = 'update';
137 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contact/dedupefind', $urlQry));
140 $urlQry['action'] = 'map';
141 $urlQry['skipped'] = $skippedCount;
142 $urlQry['merged'] = $mergedCount;
143 CRM_Utils_System
::jsRedirect(
144 CRM_Utils_System
::url('civicrm/contact/dedupefind', $urlQry),
145 ts('Batch Merge Task in progress'),
146 ts('The batch merge task is still in progress. This page will be refreshed automatically.')
151 if ($action & CRM_Core_Action
::UPDATE ||
152 $action & CRM_Core_Action
::BROWSE
154 $this->action
= CRM_Core_Action
::UPDATE
;
156 $urlQry['snippet'] = 4;
158 $this->assign('sourceUrl', CRM_Utils_System
::url('civicrm/ajax/dedupefind', $urlQry, FALSE, NULL, FALSE));
160 $stats = CRM_Dedupe_Merger
::getMergeStats($cacheKeyString);
162 $message = CRM_Dedupe_Merger
::getMergeStatsMsg($stats);
163 $status = empty($stats['skipped']) ?
'success' : 'alert';
164 CRM_Core_Session
::setStatus($message, ts('Batch Complete'), $status, ['expires' => 0]);
165 // reset so we not displaying same message again
166 CRM_Dedupe_Merger
::resetMergeStats($cacheKeyString);
169 $this->_mainContacts
= CRM_Dedupe_Merger
::getDuplicatePairs($rgid, $gid, !$isConflictMode, 0, $this->isSelected(), $isConflictMode, $criteria, TRUE, $limit);
171 if (empty($this->_mainContacts
)) {
172 if ($isConflictMode) {
173 // if the current screen was intended to list only selected contacts, move back to full dupe list
174 $urlQry['action'] = 'update';
175 unset($urlQry['snippet']);
176 CRM_Utils_System
::redirect(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), $urlQry));
178 $ruleGroupName = civicrm_api3('RuleGroup', 'getvalue', ['id' => $rgid, 'return' => 'name']);
179 CRM_Core_Session
::singleton()->setStatus(ts('No possible duplicates were found using %1 rule.', [1 => $ruleGroupName]), ts('None Found'), 'info');
180 $url = CRM_Utils_System
::url('civicrm/contact/deduperules', 'reset=1');
181 if ($context == 'search') {
182 $url = CRM_Core_Session
::singleton()->readUserContext();
184 CRM_Utils_System
::redirect($url);
187 $urlQry['action'] = 'update';
189 $urlQry['cid'] = $this->_cid
;
190 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url('civicrm/contact/deduperules',
195 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url('civicrm/contact/dedupefind',
201 $this->assign('action', $this->action
);
205 $this->action
= CRM_Core_Action
::UPDATE
;
206 $this->edit($this->action
);
207 $this->assign('action', $this->action
);
209 $this->assign('context', $context);
211 return parent
::run();
215 * Browse all rule groups.
217 public function browse() {
218 $this->assign('main_contacts', $this->_mainContacts
);
221 $this->assign('cid', $this->_cid
);
223 if (isset($this->_gid
) ||
$this->_gid
) {
224 $this->assign('gid', $this->_gid
);
226 $this->assign('rgid', $this->_rgid
);
230 * Get name of edit form.
233 * classname of edit form
235 public function editForm() {
236 return 'CRM_Contact_Form_DedupeFind';
240 * Get edit form name.
245 public function editName() {
257 public function userContext($mode = NULL) {
258 return 'civicrm/contact/dedupefind';