[DsServiceBundle] add ServiceLoadDataExtesion#57
Conversation
marioprudhomme
left a comment
There was a problem hiding this comment.
A few things to consider before merging.
| @@ -0,0 +1,8 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
There was a problem hiding this comment.
Omit phpstorm related files.
| use Oro\Bundle\LocaleBundle\Entity\Repository\LocalizationRepository; | ||
|
|
||
| /** | ||
| * Class ServiceExtension |
There was a problem hiding this comment.
Update documentation with correct class name.
| if (array_key_exists('prototype', $data)) { | ||
| $item += $data['prototype']; | ||
| } | ||
| $serviceBpm = new ServiceBpm(); |
There was a problem hiding this comment.
Space missing after if condition.
| } | ||
| $serviceBpm = new ServiceBpm(); | ||
|
|
||
| #region TITLES |
There was a problem hiding this comment.
Titles, Descriptions, Buttons and Presentations block could be refactored into one common block using some kind of loop.
| foreach ($data['services'] as $item) { | ||
| if (array_key_exists('prototype', $data)) { | ||
| $item += $data['prototype']; | ||
| } |
There was a problem hiding this comment.
Space missing after if condition.
| @@ -0,0 +1,20 @@ | |||
| parameters: | |||
| ds.localization.repository: Oro\Bundle\LocaleBundle\Entity\Repository\LocalizationRepository | |||
There was a problem hiding this comment.
Is this parameter sitll being used?
| # tags: | ||
| # - { name: oro_migration.extension, extension_name: role } | ||
|
|
||
| # ds.service.migration.extension.user: |
There was a problem hiding this comment.
Remove unneeded comment below.
| class: Ds\Bundle\ServiceBundle\Migration\Extension\ServiceExtension | ||
| arguments: | ||
| - @oro_locale.repository.localization | ||
| ds.service.bpm.migration.extension.service: |
There was a problem hiding this comment.
Move this config below and related files to ServiceBpmBundle folder.
| @@ -0,0 +1,48 @@ | |||
| services: | |||
There was a problem hiding this comment.
We have removed all Data/ORM related migrations to a Demo bundle in the platform-application repository. Also, this is a client specific migration meaning it should be moved to your client project.
| @@ -0,0 +1,53 @@ | |||
| services: | |||
There was a problem hiding this comment.
We have removed all Data/ORM related migrations to a Demo bundle in the platform-application repository. Also, this is a client specific migration meaning it should be moved to your client project.
marioprudhomme
left a comment
There was a problem hiding this comment.
More details provided.
|
|
||
| $service = new Service(); | ||
|
|
||
| //Get all localizations |
There was a problem hiding this comment.
Currently, line 54, 60, etc potentially causes warnings.
Originally, the logic was being duplicated 4 times, one for each translated fields. Ideally, the refactor should be based on the translated fields, like below. Refactoring based on the localization still leaves duplicated logic for each fields like the original issue.
Here is a sample of what I'm suggesting:
foreach ([ 'titles', 'descriptions', 'buttons', 'prensentations' ] as $field) {
// original generic translated field logic you wrote...
foreach ($item[$field] as $localeValue) {
+ //If location for title exists in .yml file
+ if ($localeValue['localization']) {
+ $locale = $localeValue['localization'];
+ $localization = $this->localizationRepository->findOneBy([ 'formattingCode' => $locale ]);
+ if ($localization) {
+ $localized = new LocalizedFallbackValue();
+ $localized->setText($localeValue['text']);
+ $localized->setLocalization($localization);
+ $titles->add($localized);
+ }
+ }
+ }
$service->{'setDefault' . $field}(...); // FYI Dynamic class methods also possible in php
}There was a problem hiding this comment.
I changed loop for Titles , Buttons, Presentations and Descriptions fileds
I changed a prototype for service (services.yml) You can see in comments of ServiceExtension.php file
Add ServiceLoadDataExtesion and ServiceBpmLoadDataExtesion (+Extesion, .yml, LoadData service)