Fixed data migration bugs in address type/country #369
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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:
3. Run installation
If a run a clean setup on a clean database till this error:
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, theLoadCountryData::getCountry
will find a$country
and the error doesn't occur.Hope my description is good enough.