Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow removing locales #15026

Merged

Conversation

jakubtobiasz
Copy link
Member

@jakubtobiasz jakubtobiasz commented May 11, 2023

Q A
Branch? 1.13
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Related tickets fixes #10183
License MIT

CleanShot 2023-06-01 at 15 26 39@2x
CleanShot 2023-06-01 at 15 27 21@2x

Only unused locales can be removed. If a locale appears in any translation, automatically, it cannot be removed.

@jakubtobiasz jakubtobiasz added the Feature New feature proposals. label May 11, 2023
@jakubtobiasz jakubtobiasz requested a review from a team as a code owner May 11, 2023 09:54
@jakubtobiasz jakubtobiasz force-pushed the SYL-2861-no-way-to-delete-locale-via-admin-cli branch from 3eeac41 to e54d117 Compare May 20, 2023 04:35
@NoResponseMate
Copy link
Contributor

I don't really see a point in limiting it only to CLI, UX-wise.
Since we can only delete not used locales, then I'd assume it'll be mostly used for accidental locales, if it'd be in UI, no problem, just click a thing on the list.
With it being in CLI, after I create a locale by mistake I need to either go on the server directly or inform someone that manages it to run the command.
It's much more hassle for the same effect. The only upside I can see is settings a cron to periodically remove unused locales, but that way can have so many potential issues that I doubt anyone would use it.

The situation would be completely different if we actually allowed deleting locales that are used, which we don't.

I'd be for changing this to solution 2, but without the conditional showing of the button, and just keeping it in line with other resources that sometimes cannot be deleted (show an error flash and leave the resource be)

@GSadee
Copy link
Member

GSadee commented May 26, 2023

I have not commented before, but after thinking about it and the comment from @NoResponseMate, I would also favour the second option. To add the ability to delete only unused locales in the admin panel, I don't really see any real benefit from adding this functionality to the CLI only 🤔

I am also interested in other opinions

@probot-autolabeler probot-autolabeler bot added Admin AdminBundle related issues and PRs. API APIs related issues and PRs. labels Jun 1, 2023
@jakubtobiasz jakubtobiasz changed the title Create RemoveLocale command Allow removing locales Jun 1, 2023
@jakubtobiasz
Copy link
Member Author

jakubtobiasz commented Jun 1, 2023

Refactored 👯‍♂️. I see behats are failing, but you can still review 🕺🏻.

@jakubtobiasz jakubtobiasz force-pushed the SYL-2861-no-way-to-delete-locale-via-admin-cli branch from 7a953bc to 49fa194 Compare June 3, 2023 07:49
src/Sylius/Bundle/LocaleBundle/Remover/LocaleRemover.php Outdated Show resolved Hide resolved
Comment on lines +72 to +84
$repository = $this->entityManager->getRepository($translationEntityInterface);

return $repository->count(['locale' => $localeCode]) > 0;
Copy link
Member

Choose a reason for hiding this comment

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

That's a lot of additional queries for simple delete. We would request up to n queries equal to the number of translatable entities in the system. Can't we base it on ForeignKeyConstraintViolationException or something similar?

Copy link
Member Author

Choose a reason for hiding this comment

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

There's no foreign key to sylius_locale.
CleanShot 2023-06-09 at 07 40 46@2x

I know it might seem like many queries, but:

  • Removing a locale is not a standard action for e-commerce (usually, store administrators don't delete a locale every morning)
  • This operation might be performed by a small group of people
  • In the best scenario it'd be only 1 query, at worst a number of *Translation entities.

I believe it won't affect any store.

@jakubtobiasz
Copy link
Member Author

@lchrusciel all changed applied.
Admin custom action -> sylius.locale.pre_delete event listener
API custom action -> decorated data persister

@jakubtobiasz jakubtobiasz force-pushed the SYL-2861-no-way-to-delete-locale-via-admin-cli branch from 7395a6e to 1c20c54 Compare June 19, 2023 13:25
features/locale/managing_locales/removing_locale.feature Outdated Show resolved Hide resolved
features/locale/managing_locales/removing_locale.feature Outdated Show resolved Hide resolved
@@ -56,6 +56,7 @@ api_platform:
Sylius\Bundle\ApiBundle\Exception\ShippingMethodCannotBeRemoved: 422
Sylius\Bundle\ApiBundle\Exception\ZoneCannotBeRemoved: 422
Sylius\Bundle\ApiBundle\Exception\CannotRemoveMenuTaxonException: 409
Sylius\Bundle\LocaleBundle\Checker\Exception\LocaleIsUsedException: 422
Copy link
Contributor

Choose a reason for hiding this comment

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

Wdyt?

Suggested change
Sylius\Bundle\LocaleBundle\Checker\Exception\LocaleIsUsedException: 422
Sylius\Bundle\LocaleBundle\Checker\Exception\LocaleInUseException: 422

Copy link
Member Author

Choose a reason for hiding this comment

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

As we don't have any standard for this, I don't have any strong opinion. I guess both names are correct.

I left the initial name, but I'm leaving this suggestion unresolved for any other opinions.

@jakubtobiasz jakubtobiasz force-pushed the SYL-2861-no-way-to-delete-locale-via-admin-cli branch 3 times, most recently from f53491e to 13c5655 Compare June 28, 2023 05:59
@jakubtobiasz jakubtobiasz force-pushed the SYL-2861-no-way-to-delete-locale-via-admin-cli branch from 13c5655 to fb9da05 Compare June 28, 2023 06:58
@TheMilek TheMilek merged commit b600c40 into Sylius:1.13 Jun 28, 2023
23 checks passed
@TheMilek
Copy link
Member

Thank you, Jacob! 🎉

@jakubtobiasz jakubtobiasz deleted the SYL-2861-no-way-to-delete-locale-via-admin-cli branch June 28, 2023 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Admin AdminBundle related issues and PRs. API APIs related issues and PRs. Feature New feature proposals.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No way to delete locale via admin/cli
7 participants