protected function _upgradeRegionList() { $this->_streamOutput->writeln('Updating regions database…'); $count = $this->_count(array($this->_regionListByCountryRenamed, $this->_regionListByCountryUpdatedCode, $this->_regionListByCountryAdded, $this->_regionListByCountryRemovedCodeInUse), 3); $item = 0; foreach ($this->_regionListByCountryRenamed as $countryCode => $regionListRenamed) { foreach ($regionListRenamed as $regionCode => $regionNames) { $regionName = $regionNames['name']; $maxMindRegion = $countryCode . $regionCode; if (!CM_Db_Db::update('cm_model_location_state', array('name' => $regionName), array('_maxmind' => $maxMindRegion))) { // For the USA, where the old numeric region codes in _maxmind have been removed from MaxMind's newer region databases $countryId = $this->_countryIdList[$countryCode]; CM_Db_Db::update('cm_model_location_state', array('name' => $regionName), array('countryId' => $countryId, 'abbreviation' => $regionCode)); } $this->_printProgressCounter(++$item, $count); } } unset($this->_regionListByCountryRenamed); foreach ($this->_regionListByCountryUpdatedCode as $countryCode => $regionListUpdatedCode) { foreach ($regionListUpdatedCode as $regionCode) { $regionId = $this->_regionIdListByCountry[$countryCode][$regionCode]; $maxMindRegion = $countryCode . $regionCode; $abbreviationRegion = 'US' === $countryCode ? $regionCode : null; CM_Db_Db::update('cm_model_location_state', array('_maxmind' => $maxMindRegion, 'abbreviation' => $abbreviationRegion), array('id' => $regionId)); $this->_printProgressCounter(++$item, $count); } } unset($this->_regionListByCountryUpdatedCode); foreach ($this->_regionListByCountryAdded as $countryCode => $regionListAdded) { $countryId = $this->_countryIdList[$countryCode]; $country = new CM_Model_Location(CM_Model_Location::LEVEL_COUNTRY, $countryId); foreach ($regionListAdded as $regionCode => $regionName) { $abbreviationRegion = 'US' === $countryCode ? $regionCode : null; $maxMindRegion = $countryCode . $regionCode; $region = CM_Model_Location::createState($country, $regionName, $abbreviationRegion, $maxMindRegion); $regionId = $region->getId(); $this->_regionIdListByCountry[$countryCode][$regionCode] = $regionId; if (isset($this->_locationTree[$countryCode]['regions'][$regionCode]['location']['maxMind'])) { $maxMind = $this->_locationTree[$countryCode]['regions'][$regionCode]['location']['maxMind']; $this->_regionIdListByMaxMind[$maxMind] = $regionId; } $this->_printProgressCounter(++$item, $count); } } unset($this->_regionListByCountryAdded); foreach ($this->_regionListByCountryRemovedCodeInUse as $countryCode => $regionListRemovedCodeInUse) { foreach ($regionListRemovedCodeInUse as $regionIdOld => $regionCode) { CM_Db_Db::delete('cm_model_location_state', array('id' => $regionIdOld)); $regionId = $this->_regionIdListByCountry[$countryCode][$regionCode]; CM_Db_Db::update('cm_model_location_city', array('stateId' => $regionId), array('stateId' => $regionIdOld)); $this->_printProgressCounter(++$item, $count); } } unset($this->_regionListByCountryRemovedCodeInUse); }
public function testCreateZip() { $country = CM_Model_Location::createCountry('Example Country', 'EC'); $state = CM_Model_Location::createState($country, 'Example State', 'ES'); $city = CM_Model_Location::createCity($state, 'Example City', 50, 100); $zip = CM_Model_Location::createZip($city, '12333', 50, 100); $this->assertSame($country->getId(), $zip->getId(CM_Model_Location::LEVEL_COUNTRY)); $this->assertSame($state->getId(), $zip->getId(CM_Model_Location::LEVEL_STATE)); $this->assertSame($city->getId(), $zip->getId(CM_Model_Location::LEVEL_CITY)); $this->assertSame('12333', $zip->getName()); $this->assertSame(array('lat' => (double) 50, 'lon' => (double) 100), $zip->getCoordinates()); }