From 05a8d2456e457d32fff90a420c50ce8382704998 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 1 Mar 2016 18:17:11 +1300 Subject: [PATCH] CRM-18128 Stop bypassing caching for state_province abbreviation --- CRM/Core/PseudoConstant.php | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index 16a6ef8933..509a3ea29d 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -77,7 +77,7 @@ class CRM_Core_PseudoConstant { * States/provinces abbreviations * @var array */ - private static $stateProvinceAbbreviation; + private static $stateProvinceAbbreviation = array(); /** * Country. @@ -738,22 +738,22 @@ class CRM_Core_PseudoConstant { * array reference of all State/Province abbreviations. */ public static function stateProvinceAbbreviation($id = FALSE, $limit = TRUE) { - if ($id > 1) { - $query = " -SELECT abbreviation + if ($id && is_numeric($id)) { + if (!array_key_exists($id, (array) self::$stateProvinceAbbreviation)) { + $query = "SELECT abbreviation FROM civicrm_state_province WHERE id = %1"; - $params = array( - 1 => array( - $id, - 'Integer', - ), - ); - return CRM_Core_DAO::singleValueQuery($query, $params); + $params = array( + 1 => array( + $id, + 'Integer', + ), + ); + self::$stateProvinceAbbreviation[$id] = CRM_Core_DAO::singleValueQuery($query, $params); + } + return self::$stateProvinceAbbreviation[$id]; } - - if (!self::$stateProvinceAbbreviation || !$id) { - + else { $whereClause = FALSE; if ($limit) { @@ -774,15 +774,6 @@ WHERE id = %1"; self::populate(self::$stateProvinceAbbreviation, 'CRM_Core_DAO_StateProvince', TRUE, 'abbreviation', 'is_active', $whereClause); } - if ($id) { - if (array_key_exists($id, self::$stateProvinceAbbreviation)) { - return self::$stateProvinceAbbreviation[$id]; - } - else { - $result = NULL; - return $result; - } - } return self::$stateProvinceAbbreviation; } -- 2.25.1