CRM-19218 Fix unindexed join by getting option values using api
authorSeamus Lee <seamuslee001@gmail.com>
Thu, 11 Aug 2016 07:03:52 +0000 (17:03 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Sat, 13 Aug 2016 21:17:37 +0000 (07:17 +1000)
CRM/Core/PseudoConstant.php

index c199cc92490f161f5dd2191efa856746f997fd0f..8e4e51b000f55dc9d87a3f09194bf8c6265352f3 100644 (file)
@@ -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()) {