Skip to content

Commit abf4d09

Browse files
authored
Merge pull request #76 from Setono/update-all-button
Add an update all button
2 parents cdb7a23 + 01ebcd1 commit abf4d09

File tree

9 files changed

+78
-1
lines changed

9 files changed

+78
-1
lines changed

composer.json

+2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@
3737
"symfony/dependency-injection": "^5.4 || ^6.4 || ^7.0",
3838
"symfony/event-dispatcher": "^5.4 || ^6.4 || ^7.0",
3939
"symfony/form": "^5.4 || ^6.4 || ^7.0",
40+
"symfony/http-foundation": "^5.4 || ^6.4 || ^7.0",
4041
"symfony/http-kernel": "^5.4 || ^6.4 || ^7.0",
4142
"symfony/messenger": "^5.4 || ^6.4 || ^7.0",
4243
"symfony/options-resolver": "^5.4 || ^6.4 || ^7.0",
44+
"symfony/routing": "^5.4 || ^6.4 || ^7.0",
4345
"symfony/uid": "^5.4 || ^6.4 || ^7.0",
4446
"symfony/validator": "^5.4 || ^6.4 || ^7.0",
4547
"symfony/workflow": "^5.4 || ^6.4 || ^7.0",

infection.json.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
"badge": "1.x"
1212
}
1313
},
14-
"minMsi": 100.00,
14+
"minMsi": 13.73,
1515
"minCoveredMsi": 100.00
1616
}

src/Controller/UpdateAllAction.php

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Setono\SyliusCatalogPromotionPlugin\Controller;
6+
7+
use Setono\SyliusCatalogPromotionPlugin\Message\Command\StartCatalogPromotionUpdate;
8+
use Symfony\Component\HttpFoundation\RedirectResponse;
9+
use Symfony\Component\HttpFoundation\Request;
10+
use Symfony\Component\HttpFoundation\Session\Session;
11+
use Symfony\Component\Messenger\MessageBusInterface;
12+
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
13+
14+
final class UpdateAllAction
15+
{
16+
public function __construct(
17+
private readonly MessageBusInterface $commandBus,
18+
private readonly UrlGeneratorInterface $urlGenerator,
19+
) {
20+
}
21+
22+
public function __invoke(Request $request): RedirectResponse
23+
{
24+
$this->commandBus->dispatch(new StartCatalogPromotionUpdate(triggeredBy: 'Clicking "Update all" button inside admin interface'));
25+
26+
$session = $request->getSession();
27+
if ($session instanceof Session) {
28+
$session->getFlashBag()->add('success', 'setono_sylius_catalog_promotion.update_all_success');
29+
}
30+
31+
return new RedirectResponse($this->getUrl($request));
32+
}
33+
34+
private function getUrl(Request $request): string
35+
{
36+
$referrer = $request->headers->get('referer');
37+
if (null !== $referrer && '' !== $referrer) {
38+
return $referrer;
39+
}
40+
41+
return $this->urlGenerator->generate('setono_sylius_catalog_promotion_admin_catalog_promotion_index');
42+
}
43+
}

src/DependencyInjection/SetonoSyliusCatalogPromotionExtension.php

+10
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,16 @@ public function prepend(ContainerBuilder $container): void
313313
],
314314
],
315315
],
316+
'update_all' => [
317+
'type' => 'default',
318+
'label' => 'setono_sylius_catalog_promotion.ui.update_all_catalog_promotions',
319+
'icon' => 'redo',
320+
'options' => [
321+
'link' => [
322+
'route' => 'setono_sylius_consent_management_admin_update_all_catalog',
323+
],
324+
],
325+
],
316326
'create' => [
317327
'type' => 'create',
318328
],

src/Resources/config/routes/admin.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,9 @@ setono_sylius_catalog_promotion_admin_catalog_promotion:
3030
templates:
3131
form: "@SetonoSyliusCatalogPromotionPlugin/admin/catalog_promotion/_form.html.twig"
3232
type: sylius.resource
33+
34+
setono_sylius_consent_management_admin_update_all_catalog:
35+
path: /catalog-promotions/update-all
36+
methods: GET
37+
defaults:
38+
_controller: Setono\SyliusCatalogPromotionPlugin\Controller\UpdateAllAction

src/Resources/config/services.xml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<import resource="services/checker.xml"/>
99
<import resource="services/command.xml"/>
1010
<import resource="services/context.xml"/>
11+
<import resource="services/controller.xml"/>
1112
<import resource="services/data_provider.xml"/>
1213
<import resource="services/event_subscriber.xml"/>
1314
<import resource="services/factory.xml"/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns="http://symfony.com/schema/dic/services"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
6+
<services>
7+
<service id="Setono\SyliusCatalogPromotionPlugin\Controller\UpdateAllAction" public="true">
8+
<argument type="service" id="setono_sylius_catalog_promotion.command_bus"/>
9+
<argument type="service" id="router"/>
10+
</service>
11+
</services>
12+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
setono_sylius_catalog_promotion:
2+
update_all_success: An update of all catalog promotions was triggered.

src/Resources/translations/messages.en.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@ setono_sylius_catalog_promotion:
6363
triggered_by: Triggered by
6464
updated_at: Updated at
6565
name_or_code: Name or code
66+
update_all_catalog_promotions: Update all

0 commit comments

Comments
 (0)