Fixed data migration bugs in address type/country #369

Merged
merged 1 commit into from Jan 19, 2016

Conversation

4 participants
@sbani
Contributor

sbani commented Dec 18, 2015

Commit message

If you added another language you got an error during migration, because
country or type tried to be insert multiple times which caused an integrity
violation.

More details

Step by step guide to reproduce the error

1. Added Bundle extension

I added a bundle named AddressBundle in my namespace which uses the OroAddressBundle as parent.

class AddressBundle extends Bundle
{
    public function getParent()
    {
        return 'OroAddressBundle';
    }
}

Added some more code like an extra migration, but it's not related to the error.

2. Added translations

I added a translation file (Resources/translations/Address/entities.de.yml) with the following content:

address_type:
    construction: Baustellen Adresse
    billing: Rechnungsadresse

3. Run installation

If a run a clean setup on a clean database till this error:

[Doctrine\DBAL\Exception\UniqueConstraintViolationException]
An exception occurred while executing 'INSERT INTO oro_dictionary_country (iso2_code, iso3_code, name) VALUES (?, ?, ?)' with params ["AD", "AND", "Andorra"]:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'AD' for key 'PRIMARY'

Conclusion

It seems like my translation file with the .de.yml ending causes a second translation to be loaded (which is not happening without the file and looks like a correct behavior).
Looking at the code:
The method LoadCountryData::getCountry checks if a country is already loaded, but there was no $manager->flush() yet, so the method always creates a new $country.

Solution

$manager->flush() after each translation. Afterwards, the LoadCountryData::getCountry will find a $country and the error doesn't occur.

Hope my description is good enough.

Sufijen Bani
Fixed data migration bugs in address type/country
If you added anouther language you got an error during migration, because
country or type tried to be insert multiple times which caused an integraty
violation
@DimaSoroka

This comment has been minimized.

Show comment
Hide comment
@DimaSoroka

DimaSoroka Dec 21, 2015

Contributor

Thanks, we'll review this shortly.

Contributor

DimaSoroka commented Dec 21, 2015

Thanks, we'll review this shortly.

@orocla

This comment has been minimized.

Show comment
Hide comment
@orocla

orocla Dec 22, 2015

Thank you for your pull request.

It looks like this may be your first contribution to an Oro, Inc. open source project, in which case you'll need to sign a Contributor License Agreement (CLA) at http://www.orocrm.com/contributor-license-agreement/

If you've already signed the CLA, it's possible we don't have your GitHub username or you're using a different email address. GitHub uses the email address you set in your local Git configuration to associate commits with your GitHub account. Please sign the CLA again using the correct GitHub username and email address or see this help article on setting the email on your git commits.

Once you've signed the CLA, please allow for about an hour for the submission to be processed.

orocla commented Dec 22, 2015

Thank you for your pull request.

It looks like this may be your first contribution to an Oro, Inc. open source project, in which case you'll need to sign a Contributor License Agreement (CLA) at http://www.orocrm.com/contributor-license-agreement/

If you've already signed the CLA, it's possible we don't have your GitHub username or you're using a different email address. GitHub uses the email address you set in your local Git configuration to associate commits with your GitHub account. Please sign the CLA again using the correct GitHub username and email address or see this help article on setting the email on your git commits.

Once you've signed the CLA, please allow for about an hour for the submission to be processed.

@orocla orocla added the cla: no label Dec 22, 2015

@orocla orocla added cla: yes and removed cla: no labels Jan 4, 2016

@oro-buildbot oro-buildbot merged commit 459e826 into oroinc:master Jan 19, 2016

1 check failed

continuous-integration/travis-ci/pr The Travis CI build could not complete due to an error
Details

@sbani sbani deleted the sbani:data-mgration-fixes branch Jan 19, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment