Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix interfaces mapping in Doctrine for admin user and shop user#10450

Merged
pamil merged 2 commits into
Sylius:1.4from
pamil:1.4-user-interface-entity-mapping
Jun 13, 2019
Merged

Fix interfaces mapping in Doctrine for admin user and shop user#10450
pamil merged 2 commits into
Sylius:1.4from
pamil:1.4-user-interface-entity-mapping

Conversation

@pamil
Copy link
Copy Markdown
Contributor

@pamil pamil commented Jun 12, 2019

Both the first and the second commit should pass before merging this PR. This assures as the changes as backwards compatible (second change resigns from BC layer).

Q A
Branch? 1.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Related tickets fixes #10447, fixes #9360, related to #10408
License MIT

@pamil pamil requested a review from a team as a code owner June 12, 2019 18:08
@pamil pamil added the Potential Bug Potential bugs or bugfixes, that needs to be reproduced. label Jun 12, 2019
@pamil pamil force-pushed the 1.4-user-interface-entity-mapping branch from bbc1f07 to 285fae9 Compare June 12, 2019 18:18
@pamil
Copy link
Copy Markdown
Contributor Author

pamil commented Jun 12, 2019

UserOAuth mappings to UserInterface is another issue that needs to be solved, but rather in a different PR.

@peterukena
Copy link
Copy Markdown

Thank you so much! 🚀

return;
}

$resolveTargetEntityListener->addMethodCall(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this does not break the AdminUser entity? As far as I see this will replace its target-entity with a ShopUser as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this PR, Sylius\Component\User\Model\UserInterface targets ShopUser entity (cause it's the last one to define Sylius\Component\User\Model\UserInterface as its interface). This will preserve backwards compatibility (could be removed in 2.0).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently at lunch, but I think I remember the AdminUser mapping using the same interface for its user-relation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct, but shop user comes next and overwrites it :)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't resolveTargetEntity replacing all occurrences of OriginalTargetEntity with NewTargetEntity and thus both AdminUser and ShopUser use the NewTargetEntity (ShopUserInterface) as its target-entity?

Copy link
Copy Markdown
Contributor Author

@pamil pamil Jun 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works like this (simplified 🎉):

$interfaces = [];
$interfaces[UserInterface::class] = AdminUser::class;
$interfaces[UserInterface::class] = ShopUser::class;

var_dump(str_replace(
  array_keys($interfaces), 
  array_values($interfaces), 
  UserInterface::class
));
// string(8) "ShopUser"

There can be only one target entity for a given interface.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait - I think thats on me.
I got ResourceBundle config and mappings mixed up.
The AdminUser and ShopUser had the same interface configured for its resource, but the ShopUser is the only one being used with UserInterface in a relation (Customer in this case).

The AdminUser::class has no target-entity for nothing, so my worries fizzle.
The ShopUser::class is (only) being used by the Customer as an inverse relation with target-entity UserInterface (which gets corrected anyways) and thus re-mapping UserInterface to ShopUserInterface (or the currently configured resource-class) in the whole application is totally fine.

My bad, thanks for your time though ❤️

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

Labels

Potential Bug Potential bugs or bugfixes, that needs to be reproduced.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants