(dev/core#217) PrevNext - Allow swapping `deleteItem()` for purposes of contact-search
authorTim Otten <totten@civicrm.org>
Mon, 2 Jul 2018 21:11:21 +0000 (14:11 -0700)
committerTim Otten <totten@civicrm.org>
Wed, 25 Jul 2018 01:15:45 +0000 (18:15 -0700)
commit744b4e344aa23fbb4655797b057244109dfb2c61
treecb96aa5e15886a6943b404b88987c8bce45de4b8
parentd379a6d907c532c6fbc92ee09ef462d2dc1ce2b2
(dev/core#217) PrevNext - Allow swapping `deleteItem()` for purposes of contact-search

The `deleteItem()` function is used by both contact-search and dedupe-merge use-cases. We can classify
several of these just based on the files:

* Contact-search use-cases. (These should be updated to use the interface.)
    * `CRM/Campaign/Selector/Search.php:     CRM_Core_BAO_PrevNextCache::deleteItem(NULL, $cacheKey, 'civicrm_contact');`
    * `CRM/Contact/Form/Search.php:          CRM_Core_BAO_PrevNextCache::deleteItem(NULL, $cacheKey);`
    * `CRM/Contact/Selector.php:             CRM_Core_BAO_PrevNextCache::deleteItem(NULL, $cacheKey, 'civicrm_contact');`
* Dedupe-merge use-cases. (These should contiue using the BAO.)
    * `CRM/Contact/Form/DedupeRules.php:     CRM_Core_BAO_PrevNextCache::deleteItem(NULL, $cacheKey);`
    * `CRM/Contact/Page/DedupeFind.php:      CRM_Core_BAO_PrevNextCache::deleteItem(NULL, CRM_Dedupe_Merger::getMergeCacheKeyString($rgid, $gid, $criteria))`
    * `CRM/Dedupe/Merger.php:                CRM_Core_BAO_PrevNextCache::deleteItem(NULL, "{$cacheKeyString}_stats");`

Additionally, there are two oddballs which are harder to categorize.

* `CRM_Contact_BAO_Contact_Utils::clearContactCaches($isEmptyPrevNextTable = FALSE)` deletes *all*
  prev-next cache-records (`CRM_Core_BAO_PrevNextCache::deleteItem();`).  It only does so in one
  scenario (as part of `CRM/Contact/Import/Form/Preview.php`), which has this explanatory comment:
  "Clear all caches, forcing any searches to recheck the ACLs or group membership as the import may
  have changed it."
* `CRM_Contact_BAO_Contact::deleteContact(...)` deletes any prev-next cache-records which
  reference a specific contact (`CRM_Core_BAO_PrevNextCache::deleteItem($id)`).
  I suppose this provides a low-grade form of referential integrity.

Part of me thinks those should be re-considered (e.g.  to use a hook/event -- and reduce the
coupling between `Contact` and `PrevNext` subsystems).  However, for purposes of dev/core#217, it
seems OK to send `deleteItem(...)` to both BAO (SQL-only) and service (SQL-or-memory) variants.
CRM/Campaign/Selector/Search.php
CRM/Contact/BAO/Contact.php
CRM/Contact/BAO/Contact/Utils.php
CRM/Contact/Form/Search.php
CRM/Contact/Selector.php
CRM/Core/PrevNextCache/Interface.php
CRM/Core/PrevNextCache/Sql.php