3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
35 class CRM_Contact_Page_DedupeMerge
extends CRM_Core_Page
{
40 * Browse batch merges.
45 public function run() {
46 $runner = self
::getRunner();
48 // Run Everything in the Queue via the Web.
49 $runner->runAllViaWeb();
52 CRM_Core_Session
::setStatus(ts('Nothing to merge.'));
60 * Build a queue of tasks by dividing dupe pairs in batches.
62 public static function getRunner() {
63 $rgid = CRM_Utils_Request
::retrieve('rgid', 'Positive', $this, FALSE, 0);
64 $gid = CRM_Utils_Request
::retrieve('gid', 'Positive', $this, FALSE, 0);
65 $action = CRM_Utils_Request
::retrieve('action', 'String', CRM_Core_DAO
::$_nullObject);
66 $mode = CRM_Utils_Request
::retrieve('mode', 'String', CRM_Core_DAO
::$_nullObject, FALSE, 'safe');
68 $contactType = CRM_Core_DAO
::getFieldValue('CRM_Dedupe_DAO_RuleGroup', $rgid, 'contact_type');
69 $cacheKeyString = "merge {$contactType}";
70 $cacheKeyString .= $rgid ?
"_{$rgid}" : '_0';
71 $cacheKeyString .= $gid ?
"_{$gid}" : '_0';
73 $urlQry = "reset=1&action=update&rgid={$rgid}";
74 $urlQry = $gid ?
($urlQry . "&gid={$gid}") : $urlQry;
76 if ($mode == 'aggressive' && !CRM_Core_Permission
::check('force merge duplicate contacts')) {
77 CRM_Core_Session
::setStatus(ts('You do not have permission to force merge duplicate contact records'), ts('Permission Denied'), 'error');
78 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contact/dedupefind', $urlQry));
81 $queue = CRM_Queue_Service
::singleton()->create(array(
82 'name' => $cacheKeyString,
88 if ($action == CRM_Core_Action
::MAP
) {
89 $where = "pn.is_selected = 1";
97 $total = CRM_Core_BAO_PrevNextCache
::getCount($cacheKeyString, NULL, $where);
100 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contact/dedupefind', $urlQry));
103 // reset merge stats, so we compute new stats
104 CRM_Dedupe_Merger
::resetMergeStats($cacheKeyString);
106 for ($i = 1; $i <= ceil($total / self
::BATCHLIMIT
); $i++
) {
107 $task = new CRM_Queue_Task(
108 array('CRM_Contact_Page_DedupeMerge', 'callBatchMerge'),
109 array($rgid, $gid, $mode, TRUE, self
::BATCHLIMIT
, $isSelected),
110 "Processed " . $i * self
::BATCHLIMIT
. " pair of duplicates out of " . $total
113 // Add the Task to the Queue
114 $queue->createItem($task);
118 $urlQry .= "&context=conflicts";
119 $runner = new CRM_Queue_Runner(array(
120 'title' => ts('Merging Duplicates..'),
122 'errorMode' => CRM_Queue_Runner
::ERROR_ABORT
,
123 'onEndUrl' => CRM_Utils_System
::url('civicrm/contact/dedupefind', $urlQry, TRUE, NULL, FALSE),
130 * Carry out batch merges.
132 public static function callBatchMerge(CRM_Queue_TaskContext
$ctx, $rgid, $gid = NULL, $mode = 'safe', $autoFlip = TRUE, $batchLimit = 1, $isSelected = 2) {
133 $result = CRM_Dedupe_Merger
::batchMerge($rgid, $gid, $mode, $autoFlip, $batchLimit, $isSelected);
135 return CRM_Queue_Task
::TASK_SUCCESS
;