From a38ebe6a0b51bdb4e66749bf6d81f101ca55027e Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Thu, 11 Aug 2016 17:03:52 +1000 Subject: [PATCH] CRM-19218 Fix unindexed join by getting option values using api --- CRM/Core/PseudoConstant.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index c199cc9249..8e4e51b000 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -1800,17 +1800,23 @@ WHERE id = %1 public static function getTaxRates() { if (!isset(Civi::$statics[__CLASS__]['taxRates'])) { Civi::$statics[__CLASS__]['taxRates'] = array(); - // Never do a copy & paste of this as the join on the option value is not indexed. - // @todo fix to resolve option values first. + $option = civicrm_api3('option_value', 'get', array( + 'sequential' => 1, + 'option_group_id' => 'account_relationship', + 'name' => 'Sales Tax Account is', + )); + if ($option['count'] !== 0) { + $where = 'AND efa.account_relationship IN (' . $option['values']['value'] . ' )'; + } + else { + $where = ''; + } $sql = " SELECT fa.tax_rate, efa.entity_id FROM civicrm_entity_financial_account efa INNER JOIN civicrm_financial_account fa ON fa.id = efa.financial_account_id - INNER JOIN civicrm_option_value cov ON cov.value = efa.account_relationship - INNER JOIN civicrm_option_group cog ON cog.id = cov.option_group_id WHERE efa.entity_table = 'civicrm_financial_type' - AND cov.name = 'Sales Tax Account is' - AND cog.name = 'account_relationship' + {$where} AND fa.is_active = 1"; $dao = CRM_Core_DAO::executeQuery($sql); while ($dao->fetch()) { -- 2.25.1