(dev/core#217) PrevNext - Allow swapping `getPositions()` for purposes of contact...
authorTim Otten <totten@civicrm.org>
Mon, 2 Jul 2018 20:32:55 +0000 (13:32 -0700)
committerTim Otten <totten@civicrm.org>
Wed, 25 Jul 2018 01:15:45 +0000 (18:15 -0700)
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
CRM/Core/PrevNextCache/Interface.php
CRM/Core/PrevNextCache/Sql.php

index 4da77a244a8551831ac29fc50254fd366d7686ba..f7e0057eefa53549ea64c6488ccd933c7cef97ed 100644 (file)
@@ -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
       );
index 364e0b402b96b05c81678595edf63fec71829067..0b1bada79d7e838ec478db8ea7e17be30d319292 100644 (file)
@@ -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);
+
 }
index 5febfe2fedc47abe7f055f95459031198b3e26a5..653bb079d367685c9e185bddc357e80cf0ddae39 100644 (file)
@@ -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);
+  }
+
 }