3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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-2016
33 class CRM_Contact_Page_DedupeFind
extends CRM_Core_Page_Basic
{
34 protected $_cid = NULL;
36 protected $_mainContacts;
45 public function getBAOName() {
46 return 'CRM_Dedupe_BAO_RuleGroup';
52 public function &links() {
56 * Browse all rule groups.
58 public function run() {
59 $gid = CRM_Utils_Request
::retrieve('gid', 'Positive', $this, FALSE, 0);
60 $action = CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 0);
61 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
62 $limit = CRM_Utils_Request
::retrieve('limit', 'Integer', $this);
63 $rgid = CRM_Utils_Request
::retrieve('rgid', 'Positive');
64 $urlQry = "reset=1&rgid={$rgid}&gid={$gid}&limit={$limit}";
65 $this->assign('urlQuery', $urlQry);
67 $session = CRM_Core_Session
::singleton();
68 $contactIds = $session->get('selectedSearchContactIds');
69 if ($context == 'search' ||
!empty($contactIds)) {
71 $this->assign('backURL', $session->readUserContext());
74 if ($action & CRM_Core_Action
::RENEW
) {
78 CRM_Core_BAO_PrevNextCache
::deleteItem(NULL, CRM_Dedupe_Merger
::getMergeCacheKeyString($rgid, $gid));
80 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contact/dedupefind', $urlQry . "&action=update"));
82 elseif ($action & CRM_Core_Action
::MAP
) {
83 // do a batch merge if requested
84 $result = CRM_Dedupe_Merger
::batchMerge($rgid, $gid, 'safe', TRUE, 75);
86 $skippedCount = CRM_Utils_Request
::retrieve('skipped', 'Positive', $this, FALSE, 0);
87 $skippedCount = $skippedCount +
count($result['skipped']);
88 $mergedCount = CRM_Utils_Request
::retrieve('merged', 'Positive', $this, FALSE, 0);
89 $mergedCount = $mergedCount +
count($result['merged']);
91 if (empty($result['merged']) && empty($result['skipped'])) {
93 if ($mergedCount >= 1) {
94 $message = ts("%1 pairs of duplicates were merged", array(1 => $mergedCount));
96 if ($skippedCount >= 1) {
97 $message = $message ?
"{$message} and " : '';
98 $message .= ts("%1 pairs of duplicates were skipped due to conflict",
99 array(1 => $skippedCount)
102 $message .= ts(" during the batch merge process with safe mode.");
103 CRM_Core_Session
::setStatus($message, ts('Merge Complete'), 'success');
104 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contact/dedupefind', $urlQry . "&action=update"));
107 $urlQry .= "&action=map&skipped={$skippedCount}&merged={$mergedCount}";
108 CRM_Utils_System
::jsRedirect(
109 CRM_Utils_System
::url('civicrm/contact/dedupefind', $urlQry),
110 ts('Batch Merge Task in progress'),
111 ts('The batch merge task is still in progress. This page will be refreshed automatically.')
116 if ($action & CRM_Core_Action
::UPDATE ||
117 $action & CRM_Core_Action
::BROWSE
119 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this, FALSE, 0);
120 $this->action
= CRM_Core_Action
::UPDATE
;
122 $urlQry .= '&snippet=4';
123 if ($context == 'conflicts') {
124 $urlQry .= "&selected=1";
127 $this->assign('sourceUrl', CRM_Utils_System
::url('civicrm/ajax/dedupefind', $urlQry, FALSE, NULL, FALSE));
129 //reload from cache table
130 $cacheKeyString = CRM_Dedupe_Merger
::getMergeCacheKeyString($rgid, $gid);
132 $stats = CRM_Dedupe_Merger
::getMergeStatsMsg($cacheKeyString);
134 CRM_Core_Session
::setStatus($stats);
135 // reset so we not displaying same message again
136 CRM_Dedupe_Merger
::resetMergeStats($cacheKeyString);
138 $join = CRM_Dedupe_Merger
::getJoinOnDedupeTable();
139 $where = "de.id IS NULL";
140 if ($context == 'conflicts') {
141 $where .= " AND pn.is_selected = 1";
143 $this->_mainContacts
= CRM_Core_BAO_PrevNextCache
::retrieve($cacheKeyString, $join, $where);
144 if (empty($this->_mainContacts
)) {
145 if ($context == 'conflicts') {
146 // if the current screen was intended to list only selected contacts, move back to full dupe list
147 CRM_Utils_System
::redirect(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), $urlQry . '&action=update'));
150 $foundDupes = $this->get("dedupe_dupes_$gid");
152 $foundDupes = CRM_Dedupe_Finder
::dupesInGroup($rgid, $gid, $limit);
154 $this->set("dedupe_dupes_$gid", $foundDupes);
156 elseif (!empty($contactIds)) {
157 $foundDupes = $this->get("search_dedupe_dupes_$gid");
159 $foundDupes = CRM_Dedupe_Finder
::dupes($rgid, $contactIds);
161 $this->get("search_dedupe_dupes_$gid", $foundDupes);
164 $foundDupes = $this->get('dedupe_dupes');
166 $foundDupes = CRM_Dedupe_Finder
::dupes($rgid, array(), TRUE, $limit);
168 $this->set('dedupe_dupes', $foundDupes);
171 $ruleGroup = new CRM_Dedupe_BAO_RuleGroup();
172 $ruleGroup->id
= $rgid;
173 $ruleGroup->find(TRUE);
175 $session = CRM_Core_Session
::singleton();
176 $session->setStatus(ts('No possible duplicates were found using %1 rule.', array(1 => $ruleGroup->name
)), ts('None Found'), 'info');
177 $url = CRM_Utils_System
::url('civicrm/contact/deduperules', 'reset=1');
178 if ($context == 'search') {
179 $url = $session->readUserContext();
181 CRM_Utils_System
::redirect($url);
184 $mainContacts = CRM_Dedupe_Finder
::parseAndStoreDupePairs($foundDupes, $cacheKeyString);
192 $this->_rgid
= $rgid;
193 $this->_mainContacts
= $mainContacts;
195 $session = CRM_Core_Session
::singleton();
197 $session->pushUserContext(CRM_Utils_System
::url('civicrm/contact/deduperules',
198 $urlQry . "&action=update&cid={$this->_cid}"
202 $session->pushUserContext(CRM_Utils_System
::url('civicrm/contact/dedupefind',
203 $urlQry . "&action=update"
215 $this->_rgid
= $rgid;
218 $this->assign('action', $this->action
);
222 $this->action
= CRM_Core_Action
::UPDATE
;
223 $this->edit($this->action
);
224 $this->assign('action', $this->action
);
226 $this->assign('context', $context);
229 return parent
::run();
233 * Browse all rule groups.
235 public function browse() {
236 $this->assign('main_contacts', $this->_mainContacts
);
239 $this->assign('cid', $this->_cid
);
241 if (isset($this->_gid
) ||
$this->_gid
) {
242 $this->assign('gid', $this->_gid
);
244 $this->assign('rgid', $this->_rgid
);
248 * Get name of edit form.
251 * classname of edit form
253 public function editForm() {
254 return 'CRM_Contact_Form_DedupeFind';
258 * Get edit form name.
263 public function editName() {
275 public function userContext($mode = NULL) {
276 return 'civicrm/contact/dedupefind';