Skip to content

Commit

Permalink
Merge pull request #10890 from eileenmcnaughton/dedupe
Browse files Browse the repository at this point in the history
Towards CRM-20155 clean up form code in order to consolidate function…
  • Loading branch information
colemanw authored Aug 31, 2017
2 parents 13c55bc + 5721d85 commit be23378
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 70 deletions.
1 change: 0 additions & 1 deletion CRM/Contact/Form/Task/Merge.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

/**
* This class provides the functionality to Merge contacts.
*
*/
class CRM_Contact_Form_Task_Merge extends CRM_Contact_Form_Task {

Expand Down
104 changes: 36 additions & 68 deletions CRM/Contact/Page/DedupeFind.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ public function run() {
$context = CRM_Utils_Request::retrieve('context', 'String', $this);
$limit = CRM_Utils_Request::retrieve('limit', 'Integer', $this);
$rgid = CRM_Utils_Request::retrieve('rgid', 'Positive', $this);
$cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE, 0);
// Using a placeholder for criteria as it is intended to be able to pass this later.
$criteria = array();
$isConflictMode = ($context == 'conflicts');
if ($cid) {
$this->_cid = $cid;
}
if ($gid) {
$this->_gid = $gid;
}
$this->_rgid = $rgid;

$urlQry = array(
'reset' => 1,
'rgid' => $rgid,
Expand All @@ -78,14 +90,14 @@ public function run() {
if ($action & CRM_Core_Action::RENEW) {
// empty cache
if ($rgid) {
CRM_Core_BAO_PrevNextCache::deleteItem(NULL, CRM_Dedupe_Merger::getMergeCacheKeyString($rgid, $gid));
CRM_Core_BAO_PrevNextCache::deleteItem(NULL, CRM_Dedupe_Merger::getMergeCacheKeyString($rgid, $gid, $criteria));
}
$urlQry['action'] = 'update';
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/dedupefind', $urlQry));
}
elseif ($action & CRM_Core_Action::MAP) {
// do a batch merge if requested
$result = CRM_Dedupe_Merger::batchMerge($rgid, $gid, 'safe', 75);
$result = CRM_Dedupe_Merger::batchMerge($rgid, $gid, 'safe', 75, 2, $criteria);

$skippedCount = CRM_Utils_Request::retrieve('skipped', 'Positive', $this, FALSE, 0);
$skippedCount = $skippedCount + count($result['skipped']);
Expand Down Expand Up @@ -123,99 +135,55 @@ public function run() {
if ($action & CRM_Core_Action::UPDATE ||
$action & CRM_Core_Action::BROWSE
) {
$cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE, 0);
$this->action = CRM_Core_Action::UPDATE;

$urlQry['snippet'] = 4;
if ($context == 'conflicts') {
if ($isConflictMode) {
$urlQry['selected'] = 1;
}

$this->assign('sourceUrl', CRM_Utils_System::url('civicrm/ajax/dedupefind', $urlQry, FALSE, NULL, FALSE));

//reload from cache table
$cacheKeyString = CRM_Dedupe_Merger::getMergeCacheKeyString($rgid, $gid);
$cacheKeyString = CRM_Dedupe_Merger::getMergeCacheKeyString($rgid, $gid, $criteria);

$stats = CRM_Dedupe_Merger::getMergeStatsMsg($cacheKeyString);
if ($stats) {
CRM_Core_Session::setStatus($stats);
// reset so we not displaying same message again
CRM_Dedupe_Merger::resetMergeStats($cacheKeyString);
}
$join = CRM_Dedupe_Merger::getJoinOnDedupeTable();
$where = "de.id IS NULL";
if ($context == 'conflicts') {
$where .= " AND pn.is_selected = 1";
}
$this->_mainContacts = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, $join, $where);

$this->_mainContacts = CRM_Dedupe_Merger::getDuplicatePairs($rgid, $gid, !$isConflictMode, 0, $isConflictMode, '', $isConflictMode, $criteria, TRUE);

if (empty($this->_mainContacts)) {
if ($context == 'conflicts') {
if ($isConflictMode) {
// if the current screen was intended to list only selected contacts, move back to full dupe list
$urlQry['action'] = 'update';
unset($urlQry['snippet']);
CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), $urlQry));
}
if ($gid) {
$foundDupes = $this->get("dedupe_dupes_$gid");
if (!$foundDupes) {
$foundDupes = CRM_Dedupe_Finder::dupesInGroup($rgid, $gid, $limit);
}
$this->set("dedupe_dupes_$gid", $foundDupes);
}
else {
$foundDupes = $this->get('dedupe_dupes');
if (!$foundDupes) {
$foundDupes = CRM_Dedupe_Finder::dupes($rgid, array(), TRUE, $limit);
}
$this->set('dedupe_dupes', $foundDupes);
}
if (!$foundDupes) {
$ruleGroup = new CRM_Dedupe_BAO_RuleGroup();
$ruleGroup->id = $rgid;
$ruleGroup->find(TRUE);

$session = CRM_Core_Session::singleton();
$session->setStatus(ts('No possible duplicates were found using %1 rule.', array(1 => $ruleGroup->name)), ts('None Found'), 'info');
$url = CRM_Utils_System::url('civicrm/contact/deduperules', 'reset=1');
if ($context == 'search') {
$url = $session->readUserContext();
}
CRM_Utils_System::redirect($url);
}
else {
$mainContacts = CRM_Dedupe_Finder::parseAndStoreDupePairs($foundDupes, $cacheKeyString);

if ($cid) {
$this->_cid = $cid;
}
if ($gid) {
$this->_gid = $gid;
}
$this->_rgid = $rgid;
$this->_mainContacts = $mainContacts;

$urlQry['action'] = 'update';
if ($this->_cid) {
$urlQry['cid'] = $this->_cid;
CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/contact/deduperules',
$urlQry
));
}
else {
CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/contact/dedupefind',
$urlQry
));
}
$ruleGroupName = civicrm_api3('RuleGroup', 'getvalue', array('id' => $rgid, 'return' => 'name'));
CRM_Core_Session::singleton()->setStatus(ts('No possible duplicates were found using %1 rule.', array(1 => $ruleGroupName)), ts('None Found'), 'info');
$url = CRM_Utils_System::url('civicrm/contact/deduperules', 'reset=1');
if ($context == 'search') {
$url = CRM_Core_Session::singleton()->readUserContext();
}
CRM_Utils_System::redirect($url);
}
else {
if ($cid) {
$this->_cid = $cid;
$urlQry['action'] = 'update';
if ($this->_cid) {
$urlQry['cid'] = $this->_cid;
CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/contact/deduperules',
$urlQry
));
}
if ($gid) {
$this->_gid = $gid;
else {
CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/contact/dedupefind',
$urlQry
));
}
$this->_rgid = $rgid;
}

$this->assign('action', $this->action);
Expand Down
5 changes: 4 additions & 1 deletion CRM/Dedupe/Merger.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,9 @@ protected static function getWhereString($batchLimit, $isSelected) {
}
// else consider all dupe pairs
// @todo Adding limit to Where??!!
$where .= " LIMIT {$batchLimit}";
if ($batchLimit) {
$where .= " LIMIT {$batchLimit}";
}
return $where;
}

Expand Down Expand Up @@ -1868,6 +1870,7 @@ public static function createMergeActivities($mainId, $otherId) {
* @param bool $reloadCacheIfEmpty
* @param int $batchLimit
* @param bool $isSelected
* Limit to selected pairs.
* @param array|string $orderByClause
* @param bool $includeConflicts
* @param array $criteria
Expand Down

0 comments on commit be23378

Please sign in to comment.