Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
8c9251b3 | 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
6a488035 TO |
32 | */ |
33 | class CRM_Contact_Page_DedupeFind extends CRM_Core_Page_Basic { | |
34 | protected $_cid = NULL; | |
35 | protected $_rgid; | |
36 | protected $_mainContacts; | |
37 | protected $_gid; | |
92241006 | 38 | protected $action; |
6a488035 TO |
39 | |
40 | /** | |
fe482240 | 41 | * Get BAO Name. |
6a488035 | 42 | * |
a6c01b45 CW |
43 | * @return string |
44 | * Classname of BAO. | |
8ef12e64 | 45 | */ |
00be9182 | 46 | public function getBAOName() { |
6a488035 TO |
47 | return 'CRM_Dedupe_BAO_RuleGroup'; |
48 | } | |
49 | ||
50 | /** | |
fe482240 | 51 | * Get action Links. |
6a488035 | 52 | */ |
ce80b209 TO |
53 | public function &links() { |
54 | } | |
6a488035 TO |
55 | |
56 | /** | |
fe482240 | 57 | * Browse all rule groups. |
6a488035 | 58 | */ |
00be9182 | 59 | public function run() { |
353ffa53 TO |
60 | $gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, FALSE, 0); |
61 | $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 0); | |
6a488035 | 62 | $context = CRM_Utils_Request::retrieve('context', 'String', $this); |
4c8b4719 | 63 | $limit = CRM_Utils_Request::retrieve('limit', 'Integer', $this); |
28c64535 | 64 | $rgid = CRM_Utils_Request::retrieve('rgid', 'Positive', $this); |
5721d85e | 65 | $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE, 0); |
66 | // Using a placeholder for criteria as it is intended to be able to pass this later. | |
67 | $criteria = array(); | |
68 | $isConflictMode = ($context == 'conflicts'); | |
69 | if ($cid) { | |
70 | $this->_cid = $cid; | |
71 | } | |
72 | if ($gid) { | |
73 | $this->_gid = $gid; | |
74 | } | |
75 | $this->_rgid = $rgid; | |
76 | ||
4a8e09b1 JM |
77 | $urlQry = array( |
78 | 'reset' => 1, | |
79 | 'rgid' => $rgid, | |
80 | 'gid' => $gid, | |
83c2e820 | 81 | 'limit' => $limit, |
4a8e09b1 | 82 | ); |
4c7de212 | 83 | $this->assign('urlQuery', CRM_Utils_System::makeQueryString($urlQry)); |
6a488035 | 84 | |
d4c035a2 | 85 | if ($context == 'search') { |
6a488035 | 86 | $context = 'search'; |
d4c035a2 | 87 | $this->assign('backURL', CRM_Core_Session::singleton()->readUserContext()); |
6a488035 TO |
88 | } |
89 | ||
90 | if ($action & CRM_Core_Action::RENEW) { | |
91 | // empty cache | |
6a488035 | 92 | if ($rgid) { |
5721d85e | 93 | CRM_Core_BAO_PrevNextCache::deleteItem(NULL, CRM_Dedupe_Merger::getMergeCacheKeyString($rgid, $gid, $criteria)); |
6a488035 | 94 | } |
4a8e09b1 JM |
95 | $urlQry['action'] = 'update'; |
96 | CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/dedupefind', $urlQry)); | |
6a488035 TO |
97 | } |
98 | elseif ($action & CRM_Core_Action::MAP) { | |
99 | // do a batch merge if requested | |
5721d85e | 100 | $result = CRM_Dedupe_Merger::batchMerge($rgid, $gid, 'safe', 75, 2, $criteria); |
6a488035 TO |
101 | |
102 | $skippedCount = CRM_Utils_Request::retrieve('skipped', 'Positive', $this, FALSE, 0); | |
103 | $skippedCount = $skippedCount + count($result['skipped']); | |
353ffa53 TO |
104 | $mergedCount = CRM_Utils_Request::retrieve('merged', 'Positive', $this, FALSE, 0); |
105 | $mergedCount = $mergedCount + count($result['merged']); | |
6a488035 TO |
106 | |
107 | if (empty($result['merged']) && empty($result['skipped'])) { | |
108 | $message = ''; | |
109 | if ($mergedCount >= 1) { | |
110 | $message = ts("%1 pairs of duplicates were merged", array(1 => $mergedCount)); | |
111 | } | |
112 | if ($skippedCount >= 1) { | |
113 | $message = $message ? "{$message} and " : ''; | |
114 | $message .= ts("%1 pairs of duplicates were skipped due to conflict", | |
115 | array(1 => $skippedCount) | |
116 | ); | |
117 | } | |
118 | $message .= ts(" during the batch merge process with safe mode."); | |
119 | CRM_Core_Session::setStatus($message, ts('Merge Complete'), 'success'); | |
4a8e09b1 JM |
120 | $urlQry['action'] = 'update'; |
121 | CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/dedupefind', $urlQry)); | |
6a488035 TO |
122 | } |
123 | else { | |
4a8e09b1 | 124 | $urlQry['action'] = 'map'; |
83c2e820 | 125 | $urlQry['skipped'] = $skippedCount; |
4a8e09b1 | 126 | $urlQry['merged'] = $mergedCount; |
6a488035 TO |
127 | CRM_Utils_System::jsRedirect( |
128 | CRM_Utils_System::url('civicrm/contact/dedupefind', $urlQry), | |
129 | ts('Batch Merge Task in progress'), | |
130 | ts('The batch merge task is still in progress. This page will be refreshed automatically.') | |
131 | ); | |
132 | } | |
133 | } | |
134 | ||
135 | if ($action & CRM_Core_Action::UPDATE || | |
136 | $action & CRM_Core_Action::BROWSE | |
137 | ) { | |
6a488035 TO |
138 | $this->action = CRM_Core_Action::UPDATE; |
139 | ||
4a8e09b1 | 140 | $urlQry['snippet'] = 4; |
5721d85e | 141 | if ($isConflictMode) { |
4a8e09b1 | 142 | $urlQry['selected'] = 1; |
63ef778e | 143 | } |
6a488035 | 144 | |
c0cc2ad4 | 145 | $this->assign('sourceUrl', CRM_Utils_System::url('civicrm/ajax/dedupefind', $urlQry)); |
6a488035 TO |
146 | |
147 | //reload from cache table | |
5721d85e | 148 | $cacheKeyString = CRM_Dedupe_Merger::getMergeCacheKeyString($rgid, $gid, $criteria); |
6a488035 | 149 | |
3743fd3d | 150 | $stats = CRM_Dedupe_Merger::getMergeStats($cacheKeyString); |
63ef778e | 151 | if ($stats) { |
3743fd3d CW |
152 | $message = CRM_Dedupe_Merger::getMergeStatsMsg($stats); |
153 | $status = empty($stats['skipped']) ? 'success' : 'alert'; | |
154 | CRM_Core_Session::setStatus($message, ts('Batch Complete'), $status, array('expires' => 0)); | |
63ef778e | 155 | // reset so we not displaying same message again |
156 | CRM_Dedupe_Merger::resetMergeStats($cacheKeyString); | |
157 | } | |
5721d85e | 158 | |
159 | $this->_mainContacts = CRM_Dedupe_Merger::getDuplicatePairs($rgid, $gid, !$isConflictMode, 0, $isConflictMode, '', $isConflictMode, $criteria, TRUE); | |
160 | ||
6a488035 | 161 | if (empty($this->_mainContacts)) { |
5721d85e | 162 | if ($isConflictMode) { |
63ef778e | 163 | // if the current screen was intended to list only selected contacts, move back to full dupe list |
4a8e09b1 | 164 | $urlQry['action'] = 'update'; |
9893cfd2 | 165 | unset($urlQry['snippet']); |
4a8e09b1 | 166 | CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), $urlQry)); |
63ef778e | 167 | } |
5721d85e | 168 | $ruleGroupName = civicrm_api3('RuleGroup', 'getvalue', array('id' => $rgid, 'return' => 'name')); |
169 | CRM_Core_Session::singleton()->setStatus(ts('No possible duplicates were found using %1 rule.', array(1 => $ruleGroupName)), ts('None Found'), 'info'); | |
170 | $url = CRM_Utils_System::url('civicrm/contact/deduperules', 'reset=1'); | |
171 | if ($context == 'search') { | |
172 | $url = CRM_Core_Session::singleton()->readUserContext(); | |
6a488035 | 173 | } |
5721d85e | 174 | CRM_Utils_System::redirect($url); |
6a488035 TO |
175 | } |
176 | else { | |
5721d85e | 177 | $urlQry['action'] = 'update'; |
178 | if ($this->_cid) { | |
179 | $urlQry['cid'] = $this->_cid; | |
180 | CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/contact/deduperules', | |
181 | $urlQry | |
182 | )); | |
6a488035 | 183 | } |
5721d85e | 184 | else { |
185 | CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/contact/dedupefind', | |
186 | $urlQry | |
187 | )); | |
6a488035 | 188 | } |
6a488035 TO |
189 | } |
190 | ||
191 | $this->assign('action', $this->action); | |
192 | $this->browse(); | |
193 | } | |
194 | else { | |
195 | $this->action = CRM_Core_Action::UPDATE; | |
196 | $this->edit($this->action); | |
197 | $this->assign('action', $this->action); | |
198 | } | |
199 | $this->assign('context', $context); | |
200 | ||
6a488035 TO |
201 | return parent::run(); |
202 | } | |
203 | ||
204 | /** | |
fe482240 | 205 | * Browse all rule groups. |
6a488035 | 206 | */ |
00be9182 | 207 | public function browse() { |
6a488035 TO |
208 | $this->assign('main_contacts', $this->_mainContacts); |
209 | ||
210 | if ($this->_cid) { | |
211 | $this->assign('cid', $this->_cid); | |
212 | } | |
213 | if (isset($this->_gid) || $this->_gid) { | |
214 | $this->assign('gid', $this->_gid); | |
215 | } | |
216 | $this->assign('rgid', $this->_rgid); | |
217 | } | |
218 | ||
219 | /** | |
fe482240 | 220 | * Get name of edit form. |
6a488035 | 221 | * |
a6c01b45 CW |
222 | * @return string |
223 | * classname of edit form | |
6a488035 | 224 | */ |
00be9182 | 225 | public function editForm() { |
6a488035 TO |
226 | return 'CRM_Contact_Form_DedupeFind'; |
227 | } | |
228 | ||
229 | /** | |
fe482240 | 230 | * Get edit form name. |
6a488035 | 231 | * |
a6c01b45 CW |
232 | * @return string |
233 | * name of this page | |
6a488035 | 234 | */ |
00be9182 | 235 | public function editName() { |
6a488035 TO |
236 | return 'DedupeFind'; |
237 | } | |
238 | ||
239 | /** | |
fe482240 | 240 | * Get user context. |
6a488035 | 241 | * |
77b97be7 EM |
242 | * @param null $mode |
243 | * | |
a6c01b45 CW |
244 | * @return string |
245 | * user context | |
6a488035 | 246 | */ |
00be9182 | 247 | public function userContext($mode = NULL) { |
6a488035 TO |
248 | return 'civicrm/contact/dedupefind'; |
249 | } | |
96025800 | 250 | |
6a488035 | 251 | } |