PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.6
Booking for Appointments and Events Calendar – Amelia v2.4.6
2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Application / Commands / Booking / Event / DeleteEventCommandHandler.php
ameliabooking / src / Application / Commands / Booking / Event Last commit date
Tag 3 months ago AddEventCommand.php 1 year ago AddEventCommandHandler.php 1 week ago DeleteEventBookingCommand.php 7 years ago DeleteEventBookingCommandHandler.php 1 week ago DeleteEventCommand.php 1 year ago DeleteEventCommandHandler.php 7 months ago DeleteEventsCommand.php 7 months ago DeleteEventsCommandHandler.php 4 months ago GenerateEventWpaCustomPostCommand.php 4 weeks ago GenerateEventWpaCustomPostCommandHandler.php 4 weeks ago GetCalendarEventsCommand.php 1 year ago GetCalendarEventsCommandHandler.php 1 week ago GetEventBookingCommand.php 7 months ago GetEventBookingCommandHandler.php 1 week ago GetEventBookingsCommand.php 1 year ago GetEventBookingsCommandHandler.php 1 week ago GetEventCommand.php 7 years ago GetEventCommandHandler.php 1 week ago GetEventsCommand.php 1 year ago GetEventsCommandHandler.php 1 week ago UpdateEventBookingCommand.php 7 years ago UpdateEventBookingCommandHandler.php 7 months ago UpdateEventCommand.php 1 year ago UpdateEventCommandHandler.php 1 week ago UpdateEventStatusCommand.php 1 year ago UpdateEventStatusCommandHandler.php 7 months ago UpdateEventVisibilityCommand.php 7 months ago UpdateEventVisibilityCommandHandler.php 7 months ago
DeleteEventCommandHandler.php
109 lines
1 <?php
2
3 namespace AmeliaBooking\Application\Commands\Booking\Event;
4
5 use AmeliaBooking\Application\Commands\CommandHandler;
6 use AmeliaBooking\Application\Commands\CommandResult;
7 use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException;
8 use AmeliaBooking\Application\Services\Booking\EventApplicationService;
9 use AmeliaBooking\Domain\Collection\Collection;
10 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
11 use AmeliaBooking\Domain\Entity\Booking\Event\Event;
12 use AmeliaBooking\Domain\Entity\Entities;
13 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
14 use AmeliaBooking\Infrastructure\Repository\Booking\Event\EventRepository;
15 use AmeliaBooking\Infrastructure\WP\EventListeners\Booking\Event\EventStatusUpdatedEventHandler;
16
17 /**
18 * Class DeleteEventCommandHandler
19 *
20 * @package AmeliaBooking\Application\Commands\Booking\Event
21 */
22 class DeleteEventCommandHandler extends CommandHandler
23 {
24 /**
25 * @param DeleteEventCommand $command
26 *
27 * @return CommandResult
28 * @throws \Slim\Exception\ContainerValueNotFoundException
29 * @throws AccessDeniedException
30 * @throws InvalidArgumentException
31 * @throws QueryExecutionException
32 */
33 public function handle(DeleteEventCommand $command)
34 {
35 if (!$command->getPermissionService()->currentUserCanDelete(Entities::EVENTS)) {
36 throw new AccessDeniedException('You are not allowed to delete event');
37 }
38
39 $result = new CommandResult();
40
41 $this->checkMandatoryFields($command);
42
43 /** @var EventApplicationService $eventApplicationService */
44 $eventApplicationService = $this->container->get('application.booking.event.service');
45
46 /** @var EventRepository $eventRepository */
47 $eventRepository = $this->container->get('domain.booking.event.repository');
48
49 $event = $eventRepository->getById($command->getArg('id'));
50
51 do_action('amelia_before_event_deleted', $event ? $event->toArray() : null);
52
53 $eventRepository->beginTransaction();
54
55 try {
56 if ($event->getStatus()->getValue() === 'approved') {
57 $events = new Collection();
58 $events->addItem($event, $event->getId()->getValue());
59 /** @var Collection $updatedEvents */
60 $updatedEvents = $eventApplicationService->updateStatus(
61 $events,
62 'rejected',
63 $command->getField('applyGlobally')
64 );
65
66 $statusResult = new CommandResult();
67 $statusResult->setResult(CommandResult::RESULT_SUCCESS);
68 $statusResult->setData(
69 [
70 'status' => 'rejected',
71 Entities::EVENTS => $updatedEvents->toArray(),
72 ]
73 );
74
75 EventStatusUpdatedEventHandler::handle($statusResult, $this->container);
76 }
77 } catch (QueryExecutionException $e) {
78 $eventRepository->rollback();
79 throw $e;
80 }
81
82 $eventRepository->commit();
83
84 $eventRepository->beginTransaction();
85
86 try {
87 $deletedEvents = $eventApplicationService->delete($event, $command->getField('applyGlobally'));
88 } catch (QueryExecutionException $e) {
89 $eventRepository->rollback();
90 throw $e;
91 }
92
93 $eventRepository->commit();
94
95 do_action('amelia_after_event_deleted', $event ? $event->toArray() : null);
96
97 $result->setResult(CommandResult::RESULT_SUCCESS);
98 $result->setMessage('Successfully deleted event');
99 $result->setData(
100 [
101 Entities::EVENT => $event->toArray(),
102 'deletedEvents' => $deletedEvents
103 ]
104 );
105
106 return $result;
107 }
108 }
109