1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Sylius\Bundle\AdminBundle\Action; |
15
|
|
|
|
16
|
|
|
use Sylius\Bundle\AdminBundle\EmailManager\ShipmentEmailManagerInterface; |
17
|
|
|
use Sylius\Component\Core\Model\ShipmentInterface; |
18
|
|
|
use Sylius\Component\Core\Repository\ShipmentRepositoryInterface; |
19
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
20
|
|
|
use Symfony\Component\HttpFoundation\Request; |
21
|
|
|
use Symfony\Component\HttpFoundation\Response; |
22
|
|
|
use Symfony\Component\HttpFoundation\Session\Session; |
23
|
|
|
use Symfony\Component\HttpFoundation\Session\SessionInterface; |
24
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException; |
25
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
26
|
|
|
use Symfony\Component\Security\Csrf\CsrfToken; |
27
|
|
|
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; |
28
|
|
|
|
29
|
|
|
final class ResendShipmentConfirmationEmailAction |
30
|
|
|
{ |
31
|
|
|
/** @var ShipmentRepositoryInterface */ |
32
|
|
|
private $shipmentRepository; |
33
|
|
|
|
34
|
|
|
/** @var ShipmentEmailManagerInterface */ |
35
|
|
|
private $shipmentEmailManager; |
36
|
|
|
|
37
|
|
|
/** @var CsrfTokenManagerInterface */ |
38
|
|
|
private $csrfTokenManager; |
39
|
|
|
|
40
|
|
|
/** @var Session */ |
41
|
|
|
private $session; |
42
|
|
|
|
43
|
|
|
public function __construct( |
44
|
|
|
ShipmentRepositoryInterface $shipmentRepository, |
45
|
|
|
ShipmentEmailManagerInterface $shipmentEmailManager, |
46
|
|
|
CsrfTokenManagerInterface $csrfTokenManager, |
47
|
|
|
SessionInterface $session |
48
|
|
|
) { |
49
|
|
|
$this->shipmentRepository = $shipmentRepository; |
50
|
|
|
$this->shipmentEmailManager = $shipmentEmailManager; |
51
|
|
|
$this->csrfTokenManager = $csrfTokenManager; |
52
|
|
|
$this->session = $session; |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function __invoke(Request $request): Response |
56
|
|
|
{ |
57
|
|
|
$shipmentId = $request->attributes->get('id'); |
58
|
|
|
|
59
|
|
|
if (!$this->csrfTokenManager->isTokenValid(new CsrfToken($shipmentId, $request->query->get('_csrf_token')))) { |
60
|
|
|
throw new HttpException(Response::HTTP_FORBIDDEN, 'Invalid csrf token.'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** @var ShipmentInterface|null $shipment */ |
64
|
|
|
$shipment = $this->shipmentRepository->find($shipmentId); |
65
|
|
|
if ($shipment === null) { |
66
|
|
|
throw new NotFoundHttpException(sprintf('The shipment with id %s has not been found', $shipmentId)); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$this->shipmentEmailManager->sendConfirmationEmail($shipment); |
70
|
|
|
|
71
|
|
|
$this->session->getFlashBag()->add( |
72
|
|
|
'success', |
73
|
|
|
'sylius.email.shipment_confirmation_resent' |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
return new RedirectResponse($request->headers->get('referer')); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..