platform
platform copied to clipboard
Installation fails when migration scripts attempts to add translation data
Summary
Upon adding translation, installation fails.
Steps to reproduce
Add data migration script that installs translation into the system. Sample code use:
/** @var TranslationManager $translationManager */ $translationManager = $this->container->get('oro_translation.manager.translation'); $catalogue = $translator->getCatalogue($locale); foreach ($translations as $domain => $translates) { foreach ($translates as $key => $translate) { $translationManager->saveTranslation($key, $translate, $locale, $domain, Translation::SCOPE_INSTALLED); $catalogue->set($key, $translate, $domain); } }
Actual Result
Installation fails with exception
In Translation.php line 104: Argument 1 passed to Oro\Bundle\TranslationBundle\Entity\Translation::set La nguage() must be an instance of Oro\Bundle\TranslationBundle\Entity\Langu ag e, null given, called in /app/vendor/oro/platform/src/Oro/Bundle/Translat io nBundle/Manager/TranslationManager.php on line 81
Expected Result
If the feature is not supported, system should provide clear error messages.
Details about your environment
- OroPlatform version: x.y.z
- PHP version: 7.3.18
- Database (PostgreSQL) version 9.6
Additional information
I did eventually move it out of migration into a command, but I thought the above handling might improve other developers experience. By the way the above was a discussion in slack orocommerce channel.
@mrfroasty The problem is not related to installation or migrations. I do not see where you define $locale in your code example. It should be a valid language code.
@mbessolov I think at the time the migration get executed, the installation has not installed the languages. But here is the original class that was tested and failed with the above error: