From d379a6d907c532c6fbc92ee09ef462d2dc1ce2b2 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 2 Jul 2018 13:32:55 -0700 Subject: [PATCH] (dev/core#217) PrevNext - Allow swapping `getPositions()` for purposes of contact-search The `getPositions()` function is used by both contact-search and dedupe-merge use-cases. ``` CRM/Contact/Form/Merge.php: $pos = CRM_Core_BAO_PrevNextCache::getPositions($cacheKey, $this->_cid, $this->_oid, $this->_mergeId, $join, $where, $flip); CRM/Contact/Form/Merge.php: $pos = CRM_Core_BAO_PrevNextCache::getPositions($cacheKey, NULL, NULL, $this->_mergeId, $join, $where); CRM/Contact/Page/View.php: $pos = CRM_Core_BAO_PrevNextCache::getPositions("civicrm search $qfKey", $this->_contactId, $this->_contactId); ``` Our aim in developing `CRM_Core_PrevNextCache_Interface` is to allow contact-search to swap a MySQL backend with a Redis backend -- and dedupe-merge should continue as-is (whether or not Redis is available). This basically means: * Contact-search switches to using `Civi::service('prevnext')->getPositions()` * Dedupe-merge continues using `CRM_Core_BAO_PrevNextCache::getPositions()` Note that the `Interface::getPositions()` is simpler than the BAO's variant. This is good because: * Contact-search doesn't need as many parameters. * Dedupe-merge still needs all the parameters. * Adding all parameters would make it hard to implement on other backends. (This is esp true of SQL-style options `$join` and `$where`.) --- CRM/Contact/Page/View.php | 2 +- CRM/Core/PrevNextCache/Interface.php | 11 +++++++++++ CRM/Core/PrevNextCache/Sql.php | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CRM/Contact/Page/View.php b/CRM/Contact/Page/View.php index 4da77a244a..f7e0057eef 100644 --- a/CRM/Contact/Page/View.php +++ b/CRM/Contact/Page/View.php @@ -117,7 +117,7 @@ class CRM_Contact_Page_View extends CRM_Core_Page { 'nextPrevError' => 0, ); if ($qfKey) { - $pos = CRM_Core_BAO_PrevNextCache::getPositions("civicrm search $qfKey", + $pos = Civi::service('prevnext')->getPositions("civicrm search $qfKey", $this->_contactId, $this->_contactId ); diff --git a/CRM/Core/PrevNextCache/Interface.php b/CRM/Core/PrevNextCache/Interface.php index 364e0b402b..0b1bada79d 100644 --- a/CRM/Core/PrevNextCache/Interface.php +++ b/CRM/Core/PrevNextCache/Interface.php @@ -84,4 +84,15 @@ interface CRM_Core_PrevNextCache_Interface { */ public function getSelection($cacheKey, $action = 'get'); + /** + * Get the previous and next keys. + * + * @param string $cacheKey + * @param int $id1 + * @param int $id2 + * + * @return array + */ + public function getPositions($cacheKey, $id1, $id2); + } diff --git a/CRM/Core/PrevNextCache/Sql.php b/CRM/Core/PrevNextCache/Sql.php index 5febfe2fed..653bb079d3 100644 --- a/CRM/Core/PrevNextCache/Sql.php +++ b/CRM/Core/PrevNextCache/Sql.php @@ -175,4 +175,20 @@ ORDER BY id } } + /** + * Get the previous and next keys. + * + * @param string $cacheKey + * @param int $id1 + * @param int $id2 + * + * NOTE: I don't really get why there are two ID columns, but we'll + * keep passing them through as a matter of safe-refactoring. + * + * @return array + */ + public function getPositions($cacheKey, $id1, $id2) { + return CRM_Core_BAO_PrevNextCache::getPositions($cacheKey, $id1, $id2); + } + } -- 2.25.1