Skip to content

Commit

Permalink
CRM-21753 add pass-through support for criteria in urls on dedupe pages
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Feb 8, 2018
1 parent 49b24c3 commit 83ab2ee
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 15 deletions.
21 changes: 14 additions & 7 deletions CRM/Contact/Form/Merge.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class CRM_Contact_Form_Merge extends CRM_Core_Form {

var $_contactType = NULL;

/**
* @var array
*/
public $criteria = array();

/**
* Query limit to be retained in the urls.
*
Expand Down Expand Up @@ -74,7 +79,9 @@ public function preProcess() {
$this->_gid = $gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, FALSE);
$this->_mergeId = CRM_Utils_Request::retrieve('mergeId', 'Positive', $this, FALSE);
$this->limit = CRM_Utils_Request::retrieve('limit', 'Positive', $this, FALSE);
$urlParams = "reset=1&rgid={$this->_rgid}&gid={$this->_gid}&limit=" . $this->limit;
$this->criteria = CRM_Utils_Request::retrieve('criteria', 'String', $this, FALSE, '{}');

$urlParams = "reset=1&rgid={$this->_rgid}&gid={$this->_gid}&limit=" . $this->limit . '&criteria=' . $this->criteria;

$this->bounceIfInvalid($this->_cid, $this->_oid);

Expand All @@ -83,7 +90,7 @@ public function preProcess() {
'return' => 'contact_type',
));

$browseUrl = CRM_Utils_System::url('civicrm/contact/dedupefind', $urlParams . '&action=browse');
$browseUrl = CRM_Utils_System::url('civicrm/contact/dedupefind', $urlParams . '&action=browse', FALSE, NULL, FALSE);

if (!$this->_rgid) {
// Unset browse URL as we have come from the search screen.
Expand All @@ -99,7 +106,7 @@ public function preProcess() {
CRM_Core_Session::singleton()->pushUserContext($browseUrl);
}

$cacheKey = CRM_Dedupe_Merger::getMergeCacheKeyString($this->_rgid, $gid);
$cacheKey = CRM_Dedupe_Merger::getMergeCacheKeyString($this->_rgid, $gid, json_decode($this->criteria, TRUE));

$join = CRM_Dedupe_Merger::getJoinOnDedupeTable();
$where = "de.id IS NULL";
Expand All @@ -126,7 +133,7 @@ public function preProcess() {
}

$flipUrl = CRM_Utils_System::url('civicrm/contact/merge',
"reset=1&action=update&cid={$this->_oid}&oid={$this->_cid}&rgid={$this->_rgid}&gid={$gid}"
"reset=1&action=update&cid={$this->_oid}&oid={$this->_cid}&rgid={$this->_rgid}&gid={$gid}&criteria={$this->criteria}"
);
if (!$flip) {
$flipUrl .= '&flip=1';
Expand Down Expand Up @@ -295,7 +302,7 @@ public function postProcess() {
CRM_Core_Session::setStatus($message, ts('Contacts Merged'), 'success');

$url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_cid}");
$urlParams = "reset=1&gid={$this->_gid}&rgid={$this->_rgid}&limit={$this->limit}";
$urlParams = "reset=1&rgid={$this->_rgid}&gid={$this->_gid}&limit=" . $this->limit . '&criteria=' . $this->criteria;

if (!empty($formValues['_qf_Merge_submit'])) {
$urlParams .= "&action=update";
Expand All @@ -309,7 +316,7 @@ public function postProcess() {
}

if ($this->next && $this->_mergeId) {
$cacheKey = CRM_Dedupe_Merger::getMergeCacheKeyString($this->_rgid, $this->_gid);
$cacheKey = CRM_Dedupe_Merger::getMergeCacheKeyString($this->_rgid, $this->_gid, json_decode($this->criteria, TRUE));

$join = CRM_Dedupe_Merger::getJoinOnDedupeTable();
$where = "de.id IS NULL";
Expand All @@ -322,7 +329,7 @@ public function postProcess() {
) {

$urlParams .= "&cid={$pos['next']['id1']}&oid={$pos['next']['id2']}&mergeId={$pos['next']['mergeId']}&action=update";
$url = CRM_Utils_System::url('civicrm/contact/merge', $urlParams);
$url = CRM_Utils_System::url('civicrm/contact/merge', $urlParams, FALSE, NULL, FALSE);
}
}

Expand Down
10 changes: 7 additions & 3 deletions CRM/Contact/Page/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,13 +646,16 @@ public static function getDedupes() {

$gid = CRM_Utils_Request::retrieve('gid', 'Positive');
$rgid = CRM_Utils_Request::retrieve('rgid', 'Positive');
$null = NULL;
$criteria = CRM_Utils_Request::retrieve('criteria', 'String', $null, FALSE, '{}');
$selected = isset($_REQUEST['selected']) ? CRM_Utils_Type::escape($_REQUEST['selected'], 'Integer') : 0;
if ($rowCount < 0) {
$rowCount = 0;
}

$whereClause = $orderByClause = '';
$cacheKeyString = CRM_Dedupe_Merger::getMergeCacheKeyString($rgid, $gid);
$cacheKeyString = CRM_Dedupe_Merger::getMergeCacheKeyString($rgid, $gid, json_decode($criteria, TRUE));

$searchRows = array();

$searchParams = self::getSearchOptionsFromRequest();
Expand Down Expand Up @@ -808,7 +811,7 @@ public static function getDedupes() {
$searchRows[$count]['weight'] = CRM_Utils_Array::value('weight', $pair);

if (!empty($pairInfo['data']['canMerge'])) {
$mergeParams = "reset=1&cid={$pairInfo['entity_id1']}&oid={$pairInfo['entity_id2']}&action=update&rgid={$rgid}&limit=" . CRM_Utils_Request::retrieve('limit', 'Integer');
$mergeParams = "reset=1&cid={$pairInfo['entity_id1']}&oid={$pairInfo['entity_id2']}&action=update&rgid={$rgid}&criteria={$criteria}&limit=" . CRM_Utils_Request::retrieve('limit', 'Integer');
if ($gid) {
$mergeParams .= "&gid={$gid}";
}
Expand Down Expand Up @@ -1007,8 +1010,9 @@ public static function toggleDedupeSelect() {
$gid = CRM_Utils_Type::escape($_REQUEST['gid'], 'Integer');
$pnid = $_REQUEST['pnid'];
$isSelected = CRM_Utils_Type::escape($_REQUEST['is_selected'], 'Boolean');
$criteria = CRM_Utils_Request::retrieve('criteria', 'String', $null, FALSE, '{}');

$cacheKeyString = CRM_Dedupe_Merger::getMergeCacheKeyString($rgid, $gid);
$cacheKeyString = CRM_Dedupe_Merger::getMergeCacheKeyString($rgid, $gid, json_decode($criteria, TRUE));

$params = array(
1 => array($isSelected, 'Boolean'),
Expand Down
7 changes: 5 additions & 2 deletions CRM/Contact/Page/DedupeFind.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ public function run() {
$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();
$criteria = CRM_Utils_Request::retrieve('criteria', 'String', $this, FALSE, '{}');
$this->assign('criteria', $criteria);

$isConflictMode = ($context == 'conflicts');
if ($cid) {
$this->_cid = $cid;
Expand All @@ -79,8 +80,10 @@ public function run() {
'rgid' => $rgid,
'gid' => $gid,
'limit' => $limit,
'criteria' => $criteria,
);
$this->assign('urlQuery', CRM_Utils_System::makeQueryString($urlQry));
$criteria = json_decode($criteria, TRUE);

if ($context == 'search') {
$context = 'search';
Expand Down
8 changes: 6 additions & 2 deletions CRM/Contact/Page/DedupeMerge.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,26 @@ public function run() {
* Build a queue of tasks by dividing dupe pairs in batches.
*/
public static function getRunner() {

$rgid = CRM_Utils_Request::retrieveValue('rgid', 'Positive');
$gid = CRM_Utils_Request::retrieveValue('gid', 'Positive');
$limit = CRM_Utils_Request::retrieveValue('limit', 'Positive');
$action = CRM_Utils_Request::retrieveValue('action', 'String');
$mode = CRM_Utils_Request::retrieveValue('mode', 'String', 'safe');

$cacheKeyString = CRM_Dedupe_Merger::getMergeCacheKeyString($rgid, $gid);
$criteria = CRM_Utils_Request::retrieve('criteria', 'String', $null, FALSE, '{}');

$urlQry = array(
'reset' => 1,
'action' => 'update',
'rgid' => $rgid,
'gid' => $gid,
'limit' => $limit,
'criteria' => $criteria,
);

$criteria = json_decode($criteria, TRUE);
$cacheKeyString = CRM_Dedupe_Merger::getMergeCacheKeyString($rgid, $gid, $criteria);

if ($mode == 'aggressive' && !CRM_Core_Permission::check('force merge duplicate contacts')) {
CRM_Core_Session::setStatus(ts('You do not have permission to force merge duplicate contact records'), ts('Permission Denied'), 'error');
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/dedupefind', $urlQry));
Expand Down
5 changes: 4 additions & 1 deletion templates/CRM/Contact/Page/DedupeFind.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,17 @@
var is_selected = CRM.$('.crm-dedupe-select-all').prop('checked') ? 1 : 0;
}
var criteria = {/literal}'{$criteria}'{literal};
criteria = criteria.length > 0 ? criteria : 0;
var dataUrl = {/literal}"{crmURL p='civicrm/ajax/toggleDedupeSelect' h=0 q='snippet=4'}"{literal};
var rgid = {/literal}"{$rgid}"{literal};
var gid = {/literal}"{$gid}"{literal};
rgid = rgid.length > 0 ? rgid : 0;
gid = gid.length > 0 ? gid : 0;
CRM.$.post(dataUrl, {pnid: id, rgid: rgid, gid: gid, is_selected: is_selected}, function (data) {
CRM.$.post(dataUrl, {pnid: id, rgid: rgid, gid: gid, is_selected: is_selected, criteria : criteria}, function (data) {
// nothing to do for now
}, 'json');
}
Expand Down

0 comments on commit 83ab2ee

Please sign in to comment.