From: eileen Date: Tue, 5 Jun 2018 05:27:50 +0000 (+1200) Subject: Pass cachekey around more & criteria less X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=9d2f6d53cdd5f06b15dbdaa844c4dbca1a5292cb;p=civicrm-core.git Pass cachekey around more & criteria less It turned out the toggleDuplicates was not working when criteria was set as the validation rule didn't work. Passing around cacheKey is easier to validate and we know the cache willbe created at the point of toggle. Use cacheKey instead in url --- diff --git a/CRM/Contact/Page/AJAX.php b/CRM/Contact/Page/AJAX.php index 937a63904f..af6fdae498 100644 --- a/CRM/Contact/Page/AJAX.php +++ b/CRM/Contact/Page/AJAX.php @@ -1017,13 +1017,9 @@ LIMIT {$offset}, {$rowCount} * Mark dupe pairs as selected from un-selected state or vice-versa, in dupe cache table. */ public static function toggleDedupeSelect() { - $rgid = CRM_Utils_Type::escape($_REQUEST['rgid'], 'Integer'); - $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', 'Json', $null, FALSE, '{}'); - - $cacheKeyString = CRM_Dedupe_Merger::getMergeCacheKeyString($rgid, $gid, json_decode($criteria, TRUE)); + $cacheKeyString = CRM_Utils_Request::retrieve('cacheKey', 'Alphanumeric', $null, FALSE); $params = array( 1 => array($isSelected, 'Boolean'), diff --git a/CRM/Contact/Page/DedupeFind.php b/CRM/Contact/Page/DedupeFind.php index 287f30ef11..a6cc014b3d 100644 --- a/CRM/Contact/Page/DedupeFind.php +++ b/CRM/Contact/Page/DedupeFind.php @@ -111,6 +111,8 @@ class CRM_Contact_Page_DedupeFind extends CRM_Core_Page_Basic { $this->assign('urlQuery', CRM_Utils_System::makeQueryString($urlQry)); $this->assign('isSelected', $this->isSelected()); $criteria = json_decode($criteria, TRUE); + $cacheKeyString = CRM_Dedupe_Merger::getMergeCacheKeyString($rgid, $gid, $criteria); + $this->assign('cacheKey', $cacheKeyString); if ($context == 'search') { $context = 'search'; @@ -120,7 +122,7 @@ class CRM_Contact_Page_DedupeFind extends CRM_Core_Page_Basic { if ($action & CRM_Core_Action::RENEW) { // empty cache if ($rgid) { - CRM_Core_BAO_PrevNextCache::deleteItem(NULL, CRM_Dedupe_Merger::getMergeCacheKeyString($rgid, $gid, $criteria)); + CRM_Core_BAO_PrevNextCache::deleteItem(NULL, $cacheKeyString); } $urlQry['action'] = 'update'; CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/dedupefind', $urlQry)); @@ -171,9 +173,6 @@ class CRM_Contact_Page_DedupeFind extends CRM_Core_Page_Basic { $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, $criteria); - $stats = CRM_Dedupe_Merger::getMergeStats($cacheKeyString); if ($stats) { $message = CRM_Dedupe_Merger::getMergeStatsMsg($stats); diff --git a/CRM/Dedupe/Merger.php b/CRM/Dedupe/Merger.php index e57e83d637..1c444e836b 100644 --- a/CRM/Dedupe/Merger.php +++ b/CRM/Dedupe/Merger.php @@ -2035,7 +2035,7 @@ INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m */ public static function getMergeCacheKeyString($rule_group_id, $group_id, $criteria = array(), $checkPermissions = TRUE) { $contactType = CRM_Dedupe_BAO_RuleGroup::getContactTypeForRuleGroup($rule_group_id); - $cacheKeyString = "merge {$contactType}"; + $cacheKeyString = "merge_{$contactType}"; $cacheKeyString .= $rule_group_id ? "_{$rule_group_id}" : '_0'; $cacheKeyString .= $group_id ? "_{$group_id}" : '_0'; $cacheKeyString .= !empty($criteria) ? md5(serialize($criteria)) : '_0'; diff --git a/templates/CRM/Contact/Page/DedupeFind.tpl b/templates/CRM/Contact/Page/DedupeFind.tpl index d5ac0f2fba..afdfe3cc7a 100644 --- a/templates/CRM/Contact/Page/DedupeFind.tpl +++ b/templates/CRM/Contact/Page/DedupeFind.tpl @@ -324,8 +324,7 @@ var is_selected = CRM.$('.crm-dedupe-select-all').prop('checked') ? 1 : 0; } - var criteria = {/literal}'{$criteria|escape}'{literal}; - criteria = criteria.length > 0 ? criteria : 0; + var cacheKey = {/literal}'{$cacheKey|escape}'{literal}; var dataUrl = {/literal}"{crmURL p='civicrm/ajax/toggleDedupeSelect' h=0 q='snippet=4'}"{literal}; var rgid = {/literal}"{$rgid}"{literal}; @@ -334,7 +333,7 @@ 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, criteria : criteria}, function (data) { + CRM.$.post(dataUrl, {pnid: id, rgid: rgid, gid: gid, is_selected: is_selected, cacheKey : cacheKey}, function (data) { // nothing to do for now }, 'json'); }