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_DedupeMerge
extends CRM_Core_Page
{
22 * Browse batch merges.
24 public function run() {
25 $runner = self
::getRunner();
27 $runner->runAllViaWeb();
30 CRM_Core_Session
::setStatus(ts('Nothing to merge.'));
36 * Build a queue of tasks by dividing dupe pairs in batches.
38 public static function getRunner() {
40 $rgid = CRM_Utils_Request
::retrieveValue('rgid', 'Positive');
41 $gid = CRM_Utils_Request
::retrieveValue('gid', 'Positive');
42 $limit = CRM_Utils_Request
::retrieveValue('limit', 'Positive');
43 $action = CRM_Utils_Request
::retrieveValue('action', 'String');
44 $mode = CRM_Utils_Request
::retrieveValue('mode', 'String', 'safe');
45 $criteria = CRM_Utils_Request
::retrieve('criteria', 'Json', $null, FALSE, '{}');
53 'criteria' => $criteria,
56 $criteria = json_decode($criteria, TRUE);
57 $cacheKeyString = CRM_Dedupe_Merger
::getMergeCacheKeyString($rgid, $gid, $criteria, TRUE, $limit);
59 if ($mode === 'aggressive' && !CRM_Core_Permission
::check('force merge duplicate contacts')) {
60 CRM_Core_Session
::setStatus(ts('You do not have permission to force merge duplicate contact records'), ts('Permission Denied'), 'error');
61 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contact/dedupefind', $urlQry));
64 $queue = CRM_Queue_Service
::singleton()->create([
65 'name' => $cacheKeyString,
71 $onlyProcessSelected = ($action == CRM_Core_Action
::MAP
) ?
1 : 0;
73 $total = CRM_Core_BAO_PrevNextCache
::getCount($cacheKeyString, NULL, ($onlyProcessSelected ?
"pn.is_selected = 1" : NULL));
76 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contact/dedupefind', $urlQry));
79 // reset merge stats, so we compute new stats
80 CRM_Dedupe_Merger
::resetMergeStats($cacheKeyString);
82 for ($i = 1; $i <= ceil($total / self
::BATCHLIMIT
); $i++
) {
83 $task = new CRM_Queue_Task(
84 ['CRM_Contact_Page_DedupeMerge', 'callBatchMerge'],
85 [$rgid, $gid, $mode, self
::BATCHLIMIT
, $onlyProcessSelected, $criteria, $limit],
86 "Processed " . $i * self
::BATCHLIMIT
. " pair of duplicates out of " . $total
89 // Add the Task to the Queue
90 $queue->createItem($task);
94 $urlQry['context'] = "conflicts";
95 if ($onlyProcessSelected) {
96 $urlQry['selected'] = 1;
98 $runner = new CRM_Queue_Runner([
99 'title' => ts('Merging Duplicates..'),
101 'errorMode' => CRM_Queue_Runner
::ERROR_ABORT
,
102 'onEndUrl' => CRM_Utils_System
::url('civicrm/contact/dedupefind', $urlQry, TRUE, NULL, FALSE),
109 * Carry out batch merges.
111 * @param \CRM_Queue_TaskContext $ctx
114 * @param string $mode
115 * 'safe' mode or 'force' mode.
116 * @param int $batchLimit
117 * @param int $isSelected
118 * @param array $criteria
119 * @param int $searchLimit
123 * @throws \CRM_Core_Exception
124 * @throws \CiviCRM_API3_Exception
125 * @throws \API_Exception
127 public static function callBatchMerge(CRM_Queue_TaskContext
$ctx, $rgid, $gid, $mode, $batchLimit, $isSelected, $criteria, $searchLimit) {
128 CRM_Dedupe_Merger
::batchMerge($rgid, $gid, $mode, $batchLimit, $isSelected, $criteria, TRUE, FALSE, $searchLimit);
129 return CRM_Queue_Task
::TASK_SUCCESS
;