3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2018
33 class CRM_Contact_Page_DedupeFind
extends CRM_Core_Page_Basic
{
34 protected $_cid = NULL;
36 protected $_mainContacts;
40 * Only display selected.
47 * Get isSelected value.
49 * This needs to be an integer of 0 or 1 or NULL for no filter.
53 public function isSelected() {
54 return ($this->selected
=== NULL) ?
NULL : (int) $this->selected
;
63 public function getBAOName() {
64 return 'CRM_Dedupe_BAO_RuleGroup';
70 public function &links() {
74 * Initialize properties from input.
76 protected function initialize() {
77 $this->selected
= CRM_Utils_Request
::retrieveValue('selected', 'Boolean');
81 * Browse all rule groups.
83 public function run() {
85 $gid = CRM_Utils_Request
::retrieve('gid', 'Positive', $this, FALSE, 0);
86 $action = CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 0);
87 $context = CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this);
88 $limit = CRM_Utils_Request
::retrieve('limit', 'Integer', $this);
89 $rgid = CRM_Utils_Request
::retrieve('rgid', 'Positive', $this);
90 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this, FALSE, 0);
92 $criteria = CRM_Utils_Request
::retrieve('criteria', 'Json', $this, FALSE, '{}');
93 $this->assign('criteria', $criteria);
95 $isConflictMode = ($context == 'conflicts');
102 $this->_rgid
= $rgid;
109 'criteria' => $criteria,
111 $this->assign('urlQuery', CRM_Utils_System
::makeQueryString($urlQry));
112 $this->assign('isSelected', $this->isSelected());
113 $criteria = json_decode($criteria, TRUE);
114 $cacheKeyString = CRM_Dedupe_Merger
::getMergeCacheKeyString($rgid, $gid, $criteria);
115 $this->assign('cacheKey', $cacheKeyString);
117 if ($context == 'search') {
119 $this->assign('backURL', CRM_Core_Session
::singleton()->readUserContext());
122 if ($action & CRM_Core_Action
::RENEW
) {
125 CRM_Core_BAO_PrevNextCache
::deleteItem(NULL, $cacheKeyString);
127 $urlQry['action'] = 'update';
128 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contact/dedupefind', $urlQry));
130 elseif ($action & CRM_Core_Action
::MAP
) {
131 // do a batch merge if requested
132 $result = CRM_Dedupe_Merger
::batchMerge($rgid, $gid, 'safe', 75, 2, $criteria);
134 $skippedCount = CRM_Utils_Request
::retrieve('skipped', 'Positive', $this, FALSE, 0);
135 $skippedCount = $skippedCount +
count($result['skipped']);
136 $mergedCount = CRM_Utils_Request
::retrieve('merged', 'Positive', $this, FALSE, 0);
137 $mergedCount = $mergedCount +
count($result['merged']);
139 if (empty($result['merged']) && empty($result['skipped'])) {
141 if ($mergedCount >= 1) {
142 $message = ts("%1 pairs of duplicates were merged", array(1 => $mergedCount));
144 if ($skippedCount >= 1) {
145 $message = $message ?
"{$message} and " : '';
146 $message .= ts("%1 pairs of duplicates were skipped due to conflict",
147 array(1 => $skippedCount)
150 $message .= ts(" during the batch merge process with safe mode.");
151 CRM_Core_Session
::setStatus($message, ts('Merge Complete'), 'success');
152 $urlQry['action'] = 'update';
153 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contact/dedupefind', $urlQry));
156 $urlQry['action'] = 'map';
157 $urlQry['skipped'] = $skippedCount;
158 $urlQry['merged'] = $mergedCount;
159 CRM_Utils_System
::jsRedirect(
160 CRM_Utils_System
::url('civicrm/contact/dedupefind', $urlQry),
161 ts('Batch Merge Task in progress'),
162 ts('The batch merge task is still in progress. This page will be refreshed automatically.')
167 if ($action & CRM_Core_Action
::UPDATE ||
168 $action & CRM_Core_Action
::BROWSE
170 $this->action
= CRM_Core_Action
::UPDATE
;
172 $urlQry['snippet'] = 4;
174 $this->assign('sourceUrl', CRM_Utils_System
::url('civicrm/ajax/dedupefind', $urlQry, FALSE, NULL, FALSE));
176 $stats = CRM_Dedupe_Merger
::getMergeStats($cacheKeyString);
178 $message = CRM_Dedupe_Merger
::getMergeStatsMsg($stats);
179 $status = empty($stats['skipped']) ?
'success' : 'alert';
180 CRM_Core_Session
::setStatus($message, ts('Batch Complete'), $status, array('expires' => 0));
181 // reset so we not displaying same message again
182 CRM_Dedupe_Merger
::resetMergeStats($cacheKeyString);
185 $this->_mainContacts
= CRM_Dedupe_Merger
::getDuplicatePairs($rgid, $gid, !$isConflictMode, 0, $this->isSelected(), '', $isConflictMode, $criteria, TRUE, $limit);
187 if (empty($this->_mainContacts
)) {
188 if ($isConflictMode) {
189 // if the current screen was intended to list only selected contacts, move back to full dupe list
190 $urlQry['action'] = 'update';
191 unset($urlQry['snippet']);
192 CRM_Utils_System
::redirect(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), $urlQry));
194 $ruleGroupName = civicrm_api3('RuleGroup', 'getvalue', array('id' => $rgid, 'return' => 'name'));
195 CRM_Core_Session
::singleton()->setStatus(ts('No possible duplicates were found using %1 rule.', array(1 => $ruleGroupName)), ts('None Found'), 'info');
196 $url = CRM_Utils_System
::url('civicrm/contact/deduperules', 'reset=1');
197 if ($context == 'search') {
198 $url = CRM_Core_Session
::singleton()->readUserContext();
200 CRM_Utils_System
::redirect($url);
203 $urlQry['action'] = 'update';
205 $urlQry['cid'] = $this->_cid
;
206 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url('civicrm/contact/deduperules',
211 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url('civicrm/contact/dedupefind',
217 $this->assign('action', $this->action
);
221 $this->action
= CRM_Core_Action
::UPDATE
;
222 $this->edit($this->action
);
223 $this->assign('action', $this->action
);
225 $this->assign('context', $context);
227 return parent
::run();
231 * Browse all rule groups.
233 public function browse() {
234 $this->assign('main_contacts', $this->_mainContacts
);
237 $this->assign('cid', $this->_cid
);
239 if (isset($this->_gid
) ||
$this->_gid
) {
240 $this->assign('gid', $this->_gid
);
242 $this->assign('rgid', $this->_rgid
);
246 * Get name of edit form.
249 * classname of edit form
251 public function editForm() {
252 return 'CRM_Contact_Form_DedupeFind';
256 * Get edit form name.
261 public function editName() {
273 public function userContext($mode = NULL) {
274 return 'civicrm/contact/dedupefind';