-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #15026 Allow removing locales (jakubtobiasz)
This PR was merged into the 1.13 branch. Discussion ---------- | 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](https://github.com/Sylius/Sylius/assets/80641364/87961cad-e9af-467c-8a22-40063e925be8) <img width="560" alt="CleanShot 2023-06-01 at 15 27 21@2x" src="https://github.com/Sylius/Sylius/assets/80641364/3a5ad0ba-cdc0-4799-9904-89bc8badf8d0"> Only unused locales can be removed. If a locale appears in any translation, automatically, it cannot be removed. Commits ------- aad14e7 Create LocaleUsageChecker service 1cbe3a9 Add Behat scenario covering removing a locale 1c4b55e Implement RemoveLocale command f71029f Fix CI 343c2ed Provide improvements after code review 7b83097 Add a delete locale API endpoint 2af0ee8 Remove RemoveLocale CLI command 3533434 Cover removing a locale via API scenarios 388d0ee Add contract tests for removing a locale 4251f06 Implement DeleteLocaleAction in the SyliusAdmin 383220b Create LocaleRemover service da96a6a Refactor the DeleteLocale action to use the LocaleRemover 7988cbe Refactor the ApiBundle's DeleteLocale action to use the LocaleRemover 11311e3 Implement the UI part of removing the locales e458531 Adjust Behat scenario for removing a locale 05bf744 Replace custom Action for Locale removing in AP with an event listener d63d179 Replace custom Action for Locale removing via API with a data persister 3d5cb02 Delete an unused LocaleRemover service 956f861 Apply ECS fixes fb9da05 Provide post-CR fixes
- Loading branch information
Showing
24 changed files
with
681 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
@managing_locales | ||
Feature: Removing locales | ||
In order to delete accidentally created locales | ||
As an Administrator | ||
I want to be able to delete locales | ||
|
||
Background: | ||
Given the store operates on a channel named "Web" with hostname "web" | ||
And that channel allows to shop using "English (United States)" and "Polish (Poland)" locales | ||
And it uses the "English (United States)" locale by default | ||
And I am logged in as an administrator | ||
|
||
@ui @api | ||
Scenario: Deleting unused locale | ||
Given the store has a product "T-Shirt banana" | ||
And this product is named "Banana T-Shirt with Minions" in the "English (United States)" locale | ||
And this product has no translation in the "Polish (Poland)" locale | ||
When I remove "Polish (Poland)" locale | ||
Then I should be informed that locale "Polish (Poland)" has been deleted | ||
And only the "English (United States)" locale should be present in the system | ||
|
||
@ui @api | ||
Scenario: Deleting a locale in use | ||
Given the store has a product "T-Shirt banana" | ||
And this product is named "Banana T-Shirt with Minions" in the "English (United States)" locale | ||
And this product is named "Koszulka Banan z Minionami" in the "Polish (Poland)" locale | ||
When I remove "Polish (Poland)" locale | ||
Then I should be informed that locale "Polish (Poland)" is in use and cannot be deleted | ||
And the "Polish (Poland)" locale should be still present in the system |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/Sylius/Bundle/AdminBundle/EventListener/LocaleListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\AdminBundle\EventListener; | ||
|
||
use Sylius\Bundle\LocaleBundle\Checker\LocaleUsageCheckerInterface; | ||
use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent; | ||
use Sylius\Component\Locale\Model\LocaleInterface; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
final class LocaleListener | ||
{ | ||
public function __construct(private LocaleUsageCheckerInterface $localeUsageChecker) | ||
{ | ||
} | ||
|
||
public function preDelete(ResourceControllerEvent $event): void | ||
{ | ||
/** @var LocaleInterface $locale */ | ||
$locale = $event->getSubject(); | ||
|
||
if (!$this->localeUsageChecker->isUsed($locale->getCode())) { | ||
return; | ||
} | ||
|
||
$event->stop('sylius.locale.delete.is_used', errorCode: Response::HTTP_UNPROCESSABLE_ENTITY); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,5 @@ sylius_grid: | |
item: | ||
update: | ||
type: update | ||
delete: | ||
type: delete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/Sylius/Bundle/AdminBundle/spec/EventListener/LocaleListenerSpec.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\Sylius\Bundle\AdminBundle\EventListener; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Sylius\Bundle\LocaleBundle\Checker\LocaleUsageCheckerInterface; | ||
use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent; | ||
use Sylius\Component\Locale\Model\LocaleInterface; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
final class LocaleListenerSpec extends ObjectBehavior | ||
{ | ||
function let(LocaleUsageCheckerInterface $localeUsageChecker): void | ||
{ | ||
$this->beConstructedWith($localeUsageChecker); | ||
} | ||
|
||
function it_does_nothing_if_locale_is_not_used( | ||
LocaleUsageCheckerInterface $localeUsageChecker, | ||
LocaleInterface $locale, | ||
ResourceControllerEvent $event, | ||
): void { | ||
$localeUsageChecker->isUsed('en_US')->willReturn(false); | ||
|
||
$locale->getCode()->willReturn('en_US'); | ||
|
||
$event->getSubject()->willReturn($locale); | ||
$event->stop()->shouldNotBeCalled(); | ||
|
||
$this->preDelete($event); | ||
} | ||
|
||
function it_stops_event_if_locale_is_used( | ||
LocaleUsageCheckerInterface $localeUsageChecker, | ||
LocaleInterface $locale, | ||
ResourceControllerEvent $event, | ||
): void { | ||
$localeUsageChecker->isUsed('en_US')->willReturn(true); | ||
|
||
$locale->getCode()->willReturn('en_US'); | ||
|
||
$event->getSubject()->willReturn($locale); | ||
$event->stop('sylius.locale.delete.is_used', 'error', [], Response::HTTP_UNPROCESSABLE_ENTITY)->shouldBeCalled(); | ||
|
||
$this->preDelete($event); | ||
} | ||
} |
Oops, something went wrong.