|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file has been created by developers from BitBag. |
|
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
|
6
|
|
|
* You can find more information about us on https://bitbag.io and write us |
|
7
|
|
|
* an email on [email protected]. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace BitBag\SyliusMolliePlugin\Controller\Action\Admin; |
|
13
|
|
|
|
|
14
|
|
|
use BitBag\SyliusMolliePlugin\Entity\MollieGatewayConfigInterface; |
|
15
|
|
|
use BitBag\SyliusMolliePlugin\Entity\MollieMethodImageInterface; |
|
16
|
|
|
use BitBag\SyliusMolliePlugin\Logger\MollieLoggerActionInterface; |
|
17
|
|
|
use BitBag\SyliusMolliePlugin\Uploader\PaymentMethodLogoUploaderInterface; |
|
18
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
19
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
|
20
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
21
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
22
|
|
|
|
|
23
|
|
|
final class DeletePaymentMethodImage |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var PaymentMethodLogoUploaderInterface */ |
|
26
|
|
|
private $logoUploader; |
|
27
|
|
|
|
|
28
|
|
|
/** @var RepositoryInterface */ |
|
29
|
|
|
private $logoRepository; |
|
30
|
|
|
|
|
31
|
|
|
/** @var EntityManagerInterface */ |
|
32
|
|
|
private $entityManager; |
|
33
|
|
|
|
|
34
|
|
|
/** @var MollieLoggerActionInterface */ |
|
35
|
|
|
private $loggerAction; |
|
36
|
|
|
|
|
37
|
|
|
public function __construct( |
|
38
|
|
|
PaymentMethodLogoUploaderInterface $logoUploader, |
|
39
|
|
|
RepositoryInterface $logoRepository, |
|
40
|
|
|
EntityManagerInterface $entityManager, |
|
41
|
|
|
MollieLoggerActionInterface $loggerAction |
|
42
|
|
|
) { |
|
43
|
|
|
$this->logoUploader = $logoUploader; |
|
44
|
|
|
$this->logoRepository = $logoRepository; |
|
45
|
|
|
$this->entityManager = $entityManager; |
|
46
|
|
|
$this->loggerAction = $loggerAction; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function __invoke(Request $request): Response |
|
50
|
|
|
{ |
|
51
|
|
|
$methodName = $request->request->get('method'); |
|
52
|
|
|
|
|
53
|
|
|
/** @var MollieGatewayConfigInterface $mollieGateway */ |
|
54
|
|
|
$mollieGateway = $this->logoRepository->findOneBy(['name' => $methodName]); |
|
55
|
|
|
|
|
56
|
|
|
/** @var MollieMethodImageInterface $customizeMethodImage */ |
|
57
|
|
|
$customizeMethodImage = $mollieGateway->getCustomizeMethodImage(); |
|
58
|
|
|
|
|
59
|
|
|
$this->logoUploader->remove($customizeMethodImage->getPath()); |
|
|
|
|
|
|
60
|
|
|
$mollieGateway->setCustomizeMethodImage(null); |
|
61
|
|
|
|
|
62
|
|
|
$this->entityManager->persist($mollieGateway); |
|
63
|
|
|
$this->entityManager->flush(); |
|
64
|
|
|
|
|
65
|
|
|
$this->loggerAction->addLog(sprintf('Deleted image from method')); |
|
66
|
|
|
|
|
67
|
|
|
return new Response(Response::$statusTexts[Response::HTTP_OK], Response::HTTP_OK); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|