From: Tim Otten Date: Mon, 2 Jul 2018 19:54:54 +0000 (-0700) Subject: (dev/core#217) PrevNext - Migrate `getSelection()` from BAO to service interface X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=b7994703fff17fd22302defe4ae2f195ee9c842d;p=civicrm-core.git (dev/core#217) PrevNext - Migrate `getSelection()` from BAO to service interface --- diff --git a/CRM/Campaign/Form/Task.php b/CRM/Campaign/Form/Task.php index a7e464ad83..5ad1593f13 100644 --- a/CRM/Campaign/Form/Task.php +++ b/CRM/Campaign/Form/Task.php @@ -65,7 +65,7 @@ class CRM_Campaign_Form_Task extends CRM_Core_Form_Task { else { $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); $cacheKey = "civicrm search {$qfKey}"; - $allCids = CRM_Core_BAO_PrevNextCache::getSelection($cacheKey, "getall"); + $allCids = Civi::service('prevnext')->getSelection($cacheKey, "getall"); $ids = array_keys($allCids[$cacheKey]); $this->assign('totalSelectedVoters', count($ids)); } diff --git a/CRM/Contact/Form/Search.php b/CRM/Contact/Form/Search.php index 5b9a2079dd..eadf418b4d 100644 --- a/CRM/Contact/Form/Search.php +++ b/CRM/Contact/Form/Search.php @@ -497,7 +497,7 @@ class CRM_Contact_Form_Search extends CRM_Core_Form_Search { if ($qfKeyParam && ($this->get('component_mode') <= CRM_Contact_BAO_Query::MODE_CONTACTS || $this->get('component_mode') == CRM_Contact_BAO_Query::MODE_CONTACTSRELATED)) { $this->addClass('crm-ajax-selection-form'); $qfKeyParam = "civicrm search {$qfKeyParam}"; - $selectedContactIdsArr = CRM_Core_BAO_PrevNextCache::getSelection($qfKeyParam); + $selectedContactIdsArr = Civi::service('prevnext')->getSelection($qfKeyParam); $selectedContactIds = array_keys($selectedContactIdsArr[$qfKeyParam]); } diff --git a/CRM/Contact/Form/Task.php b/CRM/Contact/Form/Task.php index 2d6e7637bf..5cacbcc77b 100644 --- a/CRM/Contact/Form/Task.php +++ b/CRM/Contact/Form/Task.php @@ -172,7 +172,7 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task { // rather than prevnext cache table for most of the task actions except export where we rebuild query to fetch // final result set if ($useTable) { - $allCids = CRM_Core_BAO_PrevNextCache::getSelection($cacheKey, "getall"); + $allCids = Civi::service('prevnext')->getSelection($cacheKey, "getall"); } else { $allCids[$cacheKey] = self::getContactIds($form); @@ -233,7 +233,7 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task { } else { // fetching selected contact ids of passed cache key - $selectedCids = CRM_Core_BAO_PrevNextCache::getSelection($cacheKey); + $selectedCids = Civi::service('prevnext')->getSelection($cacheKey); foreach ($selectedCids[$cacheKey] as $selectedCid => $ignore) { if ($useTable) { $insertString[] = " ( {$selectedCid} ) "; diff --git a/CRM/Contact/Page/AJAX.php b/CRM/Contact/Page/AJAX.php index 031e04fb69..8270d7b753 100644 --- a/CRM/Contact/Page/AJAX.php +++ b/CRM/Contact/Page/AJAX.php @@ -978,7 +978,7 @@ LIMIT {$offset}, {$rowCount} $action = ($state == 'checked') ? 'select' : 'unselect'; Civi::service('prevnext')->markSelection($cacheKey, $action, $cId); } - $contactIds = CRM_Core_BAO_PrevNextCache::getSelection($cacheKey); + $contactIds = Civi::service('prevnext')->getSelection($cacheKey); $countSelectionCids = count($contactIds[$cacheKey]); $arrRet = array('getCount' => $countSelectionCids); diff --git a/CRM/Core/BAO/PrevNextCache.php b/CRM/Core/BAO/PrevNextCache.php index 3c330ef418..95b90b8e9d 100644 --- a/CRM/Core/BAO/PrevNextCache.php +++ b/CRM/Core/BAO/PrevNextCache.php @@ -438,47 +438,18 @@ AND c.created_date < date_sub( NOW( ), INTERVAL %2 day ) CRM_Core_DAO::executeQuery($sql, $params); } + /** * Get the selections. * - * @param string $cacheKey - * Cache key. - * @param string $action - * Action. - * $action : get - get only selection records - * getall - get all the records of the specified cache key - * @param string $entity_table - * Entity table. + * NOTE: This stub has been preserved because one extension in `universe` + * was referencing the function. * - * @return array|NULL + * @deprecated + * @see CRM_Core_PrevNextCache_Sql::getSelection() */ public static function getSelection($cacheKey, $action = 'get', $entity_table = 'civicrm_contact') { - if (!$cacheKey) { - return NULL; - } - $params = array(); - - $entity_whereClause = " AND entity_table = '{$entity_table}'"; - if ($cacheKey && ($action == 'get' || $action == 'getall')) { - $actionGet = ($action == "get") ? " AND is_selected = 1 " : ""; - $sql = " -SELECT entity_id1, entity_id2 FROM civicrm_prevnext_cache -WHERE cacheKey LIKE %1 - $actionGet - $entity_whereClause -ORDER BY id -"; - $params[1] = array("{$cacheKey}%", 'String'); - - $contactIds = array($cacheKey => array()); - $cIdDao = CRM_Core_DAO::executeQuery($sql, $params); - while ($cIdDao->fetch()) { - if ($cIdDao->entity_id1 == $cIdDao->entity_id2) { - $contactIds[$cacheKey][$cIdDao->entity_id1] = 1; - } - } - return $contactIds; - } + return Civi::service('prevnext')->getSelection($cacheKey, $action, $entity_table); } /** diff --git a/CRM/Core/PrevNextCache/Interface.php b/CRM/Core/PrevNextCache/Interface.php index fbc937b8ce..161120ca00 100644 --- a/CRM/Core/PrevNextCache/Interface.php +++ b/CRM/Core/PrevNextCache/Interface.php @@ -72,4 +72,20 @@ interface CRM_Core_PrevNextCache_Interface { */ public function markSelection($cacheKey, $action = 'unselect', $cIds = NULL, $entity_table = 'civicrm_contact'); + /** + * Get the selections. + * + * @param string $cacheKey + * Cache key. + * @param string $action + * Action. + * $action : get - get only selection records + * getall - get all the records of the specified cache key + * @param string $entity_table + * Entity table. + * + * @return array|NULL + */ + public function getSelection($cacheKey, $action = 'get', $entity_table = 'civicrm_contact'); + } diff --git a/CRM/Core/PrevNextCache/Sql.php b/CRM/Core/PrevNextCache/Sql.php index 1f3e0a2c31..2bf5242fc3 100644 --- a/CRM/Core/PrevNextCache/Sql.php +++ b/CRM/Core/PrevNextCache/Sql.php @@ -132,4 +132,47 @@ WHERE cacheKey LIKE %1 AND is_selected = 1 CRM_Core_DAO::executeQuery($sql, $params); } + /** + * Get the selections. + * + * @param string $cacheKey + * Cache key. + * @param string $action + * Action. + * $action : get - get only selection records + * getall - get all the records of the specified cache key + * @param string $entity_table + * Entity table. + * + * @return array|NULL + */ + public function getSelection($cacheKey, $action = 'get', $entity_table = 'civicrm_contact') { + if (!$cacheKey) { + return NULL; + } + $params = array(); + + $entity_whereClause = " AND entity_table = '{$entity_table}'"; + if ($cacheKey && ($action == 'get' || $action == 'getall')) { + $actionGet = ($action == "get") ? " AND is_selected = 1 " : ""; + $sql = " +SELECT entity_id1, entity_id2 FROM civicrm_prevnext_cache +WHERE cacheKey LIKE %1 + $actionGet + $entity_whereClause +ORDER BY id +"; + $params[1] = array("{$cacheKey}%", 'String'); + + $contactIds = array($cacheKey => array()); + $cIdDao = CRM_Core_DAO::executeQuery($sql, $params); + while ($cIdDao->fetch()) { + if ($cIdDao->entity_id1 == $cIdDao->entity_id2) { + $contactIds[$cacheKey][$cIdDao->entity_id1] = 1; + } + } + return $contactIds; + } + } + }