-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathDeleteAction.php
More file actions
41 lines (33 loc) · 1.34 KB
/
DeleteAction.php
File metadata and controls
41 lines (33 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
declare(strict_types=1);
namespace AppBundle\Controller\Admin\Event\Ticket;
use AppBundle\AuditLog\Audit;
use AppBundle\Event\Model\Repository\InvoiceRepository;
use AppBundle\Event\Model\Repository\TicketRepository;
use AppBundle\Event\Model\Ticket;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
final class DeleteAction extends AbstractController
{
public function __construct(
private readonly TicketRepository $ticketRepository,
private readonly InvoiceRepository $invoiceRepository,
private readonly Audit $audit,
) {}
public function __invoke(int $id, Request $request): Response
{
$ticket = $this->ticketRepository->get($id);
if (!$ticket instanceof Ticket) {
throw $this->createNotFoundException(sprintf('Ticket not found with id "%s"', $id));
}
$invoice = $this->invoiceRepository->getByReference($id);
if ($invoice) {
$this->invoiceRepository->delete($invoice);
}
$this->ticketRepository->delete($ticket);
$this->audit->log("Suppression de l'inscription " . $id);
$this->addFlash('notice', "L'inscription a été supprimée");
return $this->redirectToRoute('admin_event_ticket_list');
}
}