Skip to content

Conversation

sbani
Copy link
Contributor

@sbani 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.

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
Copy link
Contributor

Thanks, we'll review this shortly.

@orocla
Copy link

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
@sbani sbani deleted the data-mgration-fixes branch January 19, 2016 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

4 participants