Page MenuHomeIn-Portal Phabricator

D448.id1175.diff
No OneTemporary

File Metadata

Created
Wed, Feb 26, 8:59 AM

D448.id1175.diff

Index: branches/5.2.x/core/units/helpers/country_states_helper.php
===================================================================
--- branches/5.2.x/core/units/helpers/country_states_helper.php
+++ branches/5.2.x/core/units/helpers/country_states_helper.php
@@ -224,23 +224,25 @@
/**
* Returns 3 symbols ISO code from 2 symbols ISO code or otherwise, when $from_short parameter is used
*
- * @param string $iso_code
- * @param bool $from_short
+ * @param string $iso_code ISO code.
+ * @param boolean $from_short From short.
+ *
* @return string
*/
- function getCountryIso($iso_code, $from_short = false)
+ public function getCountryIso($iso_code, $from_short = false)
{
- if ($from_short) {
- $sql = 'SELECT IsoCode
- FROM ' . TABLE_PREFIX . 'CountryStates
- WHERE ShortIsoCode = ' . $this->Conn->qstr($iso_code) . ' AND `Type` = ' . DESTINATION_TYPE_COUNTRY;
- }
- else {
- $sql = 'SELECT ShortIsoCode
+ $cache_key = 'country_iso_mapping[%CountryStateSerial%]';
+ $cache_value = $this->Application->getCache($cache_key);
+
+ if ( $cache_value === false ) {
+ $sql = 'SELECT IsoCode, ShortIsoCode
FROM ' . TABLE_PREFIX . 'CountryStates
- WHERE IsoCode = ' . $this->Conn->qstr($iso_code) . ' AND `Type` = ' . DESTINATION_TYPE_COUNTRY;
+ WHERE `Type` = ' . DESTINATION_TYPE_COUNTRY;
+ $cache_value = $this->Conn->GetCol($sql, 'ShortIsoCode');
+ $this->Application->setCache($cache_key, $cache_value);
}
- return $this->Conn->GetOne($sql);
+ return $from_short ? $cache_value[$iso_code] : array_search($iso_code, $cache_value);
}
+
}

Event Timeline