-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
548 changed files
with
39,338 additions
and
11,781 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
CHANGELOG for 1.0.0-alpha3 | ||
=================== | ||
|
||
This changelog references the relevant changes (new features, changes and bugs) done in 1.0.0-alpha3 versions. | ||
|
||
* 1.0.0-alpha3 (2013-06-27) | ||
* Placeholders | ||
* Developer toolbar works with AJAX navigation requests | ||
* Configuring hidden columns in a Grid | ||
* Auto-complete form type | ||
* Added Address Book | ||
* Localized countries and regions | ||
* Enhanced data change log with ability to save changes for collections | ||
* Removed dependency on lib ICU | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
UPGRADE FROM 1.0.0-alpha2 to 1.0.0-alpha3 | ||
======================= | ||
|
||
### General | ||
|
||
* Upgrade to 1.0.0-alpha3 is not supported and full reinstall is required | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
231 changes: 231 additions & 0 deletions
231
src/Oro/Bundle/AddressBundle/DataFixtures/ORM/LoadCountryData.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,231 @@ | ||
<?php | ||
|
||
namespace Oro\Bundle\AddressBundle\DataFixtures\ORM; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Symfony\Component\DependencyInjection\ContainerAwareInterface; | ||
use Symfony\Component\Yaml\Yaml; | ||
use Symfony\Component\Translation\TranslatorInterface; | ||
use Symfony\Component\Finder\Finder; | ||
use Doctrine\Common\DataFixtures\AbstractFixture; | ||
use Doctrine\Common\Persistence\ObjectManager; | ||
use Doctrine\ORM\EntityManager; | ||
use Doctrine\ORM\EntityRepository; | ||
|
||
use Oro\Bundle\AddressBundle\Entity\Country; | ||
use Oro\Bundle\AddressBundle\Entity\Region; | ||
|
||
class LoadCountryData extends AbstractFixture implements ContainerAwareInterface | ||
{ | ||
const COUNTRY_DOMAIN = 'countries'; | ||
const COUNTRY_FILE_REGEXP = '/^countries\.(.*?)\./'; | ||
|
||
/** | ||
* @var ContainerInterface | ||
*/ | ||
protected $container; | ||
|
||
/** | ||
* @var TranslatorInterface | ||
*/ | ||
protected $translator; | ||
|
||
/** | ||
* @var EntityRepository | ||
*/ | ||
protected $countryRepository; | ||
|
||
/** | ||
* @var EntityRepository | ||
*/ | ||
protected $regionRepository; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $translationDirectory = '/Resources/translations/'; | ||
|
||
/** | ||
* @param ObjectManager $manager | ||
*/ | ||
public function load(ObjectManager $manager) | ||
{ | ||
$this->translator = $this->container->get('translator'); | ||
|
||
$fileName = $this->getFileName(); | ||
$countries = $this->getDataFromFile($fileName); | ||
$this->saveCountryData($manager, $countries); | ||
} | ||
|
||
public function setContainer(ContainerInterface $container = null) | ||
{ | ||
$this->container = $container; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getFileName() | ||
{ | ||
return __DIR__ . '/../data/countries.yml'; | ||
} | ||
|
||
/** | ||
* @param string $fileName | ||
* @return bool | ||
*/ | ||
protected function isFileAvailable($fileName) | ||
{ | ||
return is_file($fileName) && is_readable($fileName); | ||
} | ||
|
||
/** | ||
* @param string $fileName | ||
* @return array | ||
* @throws \LogicException | ||
*/ | ||
protected function getDataFromFile($fileName) | ||
{ | ||
if (!$this->isFileAvailable($fileName)) { | ||
throw new \LogicException('File ' . $fileName . 'is not available'); | ||
} | ||
|
||
$fileName = realpath($fileName); | ||
|
||
return Yaml::parse($fileName); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
protected function getAvailableCountryLocales() | ||
{ | ||
$translationDirectory = str_replace('/', DIRECTORY_SEPARATOR, $this->translationDirectory); | ||
$translationDirectories = array(); | ||
|
||
foreach ($this->container->getParameter('kernel.bundles') as $bundle) { | ||
$reflection = new \ReflectionClass($bundle); | ||
$bundleTranslationDirectory = dirname($reflection->getFilename()) . $translationDirectory; | ||
if (is_dir($bundleTranslationDirectory) && is_readable($bundleTranslationDirectory)) { | ||
$translationDirectories[] = realpath($bundleTranslationDirectory); | ||
} | ||
} | ||
|
||
$finder = new Finder(); | ||
$finder->in($translationDirectories)->name(self::COUNTRY_FILE_REGEXP); | ||
|
||
$countryLocales = array(); | ||
/** @var $file \SplFileInfo */ | ||
foreach ($finder as $file) { | ||
preg_match(self::COUNTRY_FILE_REGEXP, $file->getFilename(), $matches); | ||
if ($matches) { | ||
$countryLocales[] = $matches[1]; | ||
} | ||
} | ||
|
||
return $countryLocales; | ||
} | ||
|
||
/** | ||
* @param string $locale | ||
* @param array $countryData | ||
* @return null|Country | ||
*/ | ||
protected function getCountry($locale, array $countryData) | ||
{ | ||
if (empty($countryData['iso2Code']) || empty($countryData['iso3Code'])) { | ||
return null; | ||
} | ||
|
||
/** @var $country Country */ | ||
$country = $this->countryRepository->findOneBy(array('iso2Code' => $countryData['iso2Code'])); | ||
if (!$country) { | ||
$country = new Country($countryData['iso2Code']); | ||
$country->setIso3Code($countryData['iso3Code']); | ||
} | ||
|
||
$countryName = $this->translator->trans( | ||
$countryData['iso2Code'], | ||
array(), | ||
self::COUNTRY_DOMAIN, | ||
$locale | ||
); | ||
|
||
$country->setLocale($locale) | ||
->setName($countryName); | ||
|
||
return $country; | ||
} | ||
|
||
/** | ||
* @param string $locale | ||
* @param Country $country | ||
* @param array $regionData | ||
* @return null|Region | ||
*/ | ||
protected function getRegion($locale, Country $country, array $regionData) | ||
{ | ||
if (empty($regionData['combinedCode']) || empty($regionData['code'])) { | ||
return null; | ||
} | ||
|
||
/** @var $region Region */ | ||
$region = $this->regionRepository->findOneBy(array('combinedCode' => $regionData['combinedCode'])); | ||
if (!$region) { | ||
$region = new Region($regionData['combinedCode']); | ||
$region->setCode($regionData['code']) | ||
->setCountry($country); | ||
} | ||
|
||
$regionName = $this->translator->trans( | ||
$regionData['combinedCode'], | ||
array(), | ||
self::COUNTRY_DOMAIN, | ||
$locale | ||
); | ||
|
||
$region->setLocale($locale) | ||
->setName($regionName); | ||
|
||
return $region; | ||
} | ||
|
||
/** | ||
* Save countries and regions to DB | ||
* | ||
* @param ObjectManager $manager | ||
* @param array $countries | ||
*/ | ||
protected function saveCountryData(ObjectManager $manager, array $countries) | ||
{ | ||
$this->countryRepository = $manager->getRepository('OroAddressBundle:Country'); | ||
$this->regionRepository = $manager->getRepository('OroAddressBundle:Region'); | ||
|
||
$countryLocales = $this->getAvailableCountryLocales(); | ||
|
||
foreach ($countryLocales as $locale) { | ||
foreach ($countries as $countryData) { | ||
$country = $this->getCountry($locale, $countryData); | ||
if (!$country) { | ||
continue; | ||
} | ||
|
||
$manager->persist($country); | ||
|
||
if (!empty($countryData['regions'])) { | ||
foreach ($countryData['regions'] as $regionData) { | ||
$region = $this->getRegion($locale, $country, $regionData); | ||
if (!$region) { | ||
continue; | ||
} | ||
|
||
$manager->persist($region); | ||
} | ||
} | ||
} | ||
|
||
$manager->flush(); | ||
$manager->clear(); | ||
} | ||
} | ||
} |
Oops, something went wrong.