From 5f262bb26124bb6be0c604ebaf1a737a12ef4e59 Mon Sep 17 00:00:00 2001 From: varshith89 Date: Wed, 18 Apr 2018 18:59:39 +0000 Subject: [PATCH] Use indices Function In DAOs Instead Of SQL Query --- api/v3/Generic/Getunique.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/api/v3/Generic/Getunique.php b/api/v3/Generic/Getunique.php index 956474533d..89bc08519e 100644 --- a/api/v3/Generic/Getunique.php +++ b/api/v3/Generic/Getunique.php @@ -40,15 +40,14 @@ function civicrm_api3_generic_getUnique($apiRequest) { $entity = _civicrm_api_get_entity_name_from_camel($apiRequest['entity']); $uniqueFields = array(); - $baoName = _civicrm_api3_get_BAO($entity); - $bao = new $baoName(); - $_entityTable = $bao->tableName(); + $dao = _civicrm_api3_get_DAO($entity); + $uFields = $dao::indices(); - $sql = 'SHOW INDEX FROM '.$_entityTable.' WHERE Non_unique = 0'; - $uFields = CRM_Core_DAO::executeQuery($sql)->fetchAll(); - foreach($uFields as $field) { - // group by Key_name to handle combination indexes - $uniqueFields[$field['Key_name']][] = $field['Column_name']; + foreach($uFields as $fieldKey => $field) { + if(!isset($field['unique']) || !$field['unique']) { + continue; + } + $uniqueFields[$fieldKey] = $field['field']; } return civicrm_api3_create_success($uniqueFields); -- 2.25.1