PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.0.2
Booking for Appointments and Events Calendar – Amelia v2.0.2
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 / DeleteEventsCommandHandler.php
ameliabooking / src / Application / Commands / Booking / Event Last commit date
AddEventCommand.php 1 year ago AddEventCommandHandler.php 1 year ago DeleteEventBookingCommand.php 7 years ago DeleteEventBookingCommandHandler.php 1 year ago DeleteEventCommand.php 1 year ago DeleteEventCommandHandler.php 6 months ago DeleteEventsCommand.php 6 months ago DeleteEventsCommandHandler.php 6 months ago GetCalendarEventsCommand.php 1 year ago GetCalendarEventsCommandHandler.php 1 year ago GetEventBookingCommand.php 6 months ago GetEventBookingCommandHandler.php 5 months ago GetEventBookingsCommand.php 1 year ago GetEventBookingsCommandHandler.php 6 months ago GetEventCommand.php 7 years ago GetEventCommandHandler.php 6 months ago GetEventDeleteEffectCommand.php 1 year ago GetEventDeleteEffectCommandHandler.php 6 months ago GetEventsCommand.php 1 year ago GetEventsCommandHandler.php 6 months ago UpdateEventBookingCommand.php 7 years ago UpdateEventBookingCommandHandler.php 6 months ago UpdateEventCommand.php 1 year ago UpdateEventCommandHandler.php 6 months ago UpdateEventStatusCommand.php 1 year ago UpdateEventStatusCommandHandler.php 6 months ago UpdateEventVisibilityCommand.php 6 months ago UpdateEventVisibilityCommandHandler.php 6 months ago
DeleteEventsCommandHandler.php
119 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\Entities;
12 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
13 use AmeliaBooking\Infrastructure\Repository\Booking\Event\EventRepository;
14 use AmeliaBooking\Infrastructure\WP\EventListeners\Booking\Event\EventStatusUpdatedEventHandler;
15
16 /**
17 * Class DeleteEventsCommandHandler
18 *
19 * @package AmeliaBooking\Application\Commands\Booking\Event
20 */
21 class DeleteEventsCommandHandler extends CommandHandler
22 {
23 /**
24 * @param DeleteEventsCommand $command
25 *
26 * @return CommandResult
27 * @throws \Slim\Exception\ContainerValueNotFoundException
28 * @throws AccessDeniedException
29 * @throws InvalidArgumentException
30 * @throws QueryExecutionException
31 * @throws \Interop\Container\Exception\ContainerException
32 */
33 public function handle(DeleteEventsCommand $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 $events = $eventApplicationService->getEventsByIds(
50 $command->getField('events'),
51 [
52 'fetchEventsPeriods' => true,
53 'fetchEventsTickets' => true,
54 'fetchEventsTags' => true,
55 'fetchEventsProviders' => true,
56 'fetchEventsImages' => true,
57 'fetchBookings' => true,
58 'fetchBookingsUsers' => true,
59 ]
60 );
61
62 do_action('amelia_before_events_deleted', $events ? $events->toArray() : null);
63
64 $eventRepository->beginTransaction();
65
66 try {
67 /** @var Collection $updatedEvents */
68 $updatedEvents = $eventApplicationService->updateStatus(
69 $events,
70 'rejected',
71 false
72 );
73
74 $statusResult = new CommandResult();
75 $statusResult->setResult(CommandResult::RESULT_SUCCESS);
76 $statusResult->setData(
77 [
78 'status' => 'rejected',
79 Entities::EVENTS => $updatedEvents->toArray(),
80 ]
81 );
82 } catch (QueryExecutionException $e) {
83 $eventRepository->rollback();
84 throw $e;
85 }
86
87 $eventRepository->commit();
88
89 EventStatusUpdatedEventHandler::handle($statusResult, $this->container);
90
91 $eventRepository->beginTransaction();
92
93 try {
94 $deletedEvents = [];
95 foreach ($events->getItems() as $event) {
96 $deletedEvents = array_merge($deletedEvents, $eventApplicationService->delete($event, $command->getField('applyGlobally'))->toArray());
97 }
98 } catch (QueryExecutionException $e) {
99 $eventRepository->rollback();
100 throw $e;
101 }
102
103 $eventRepository->commit();
104
105 do_action('amelia_after_events_deleted', $deletedEvents);
106
107 $result->setResult(CommandResult::RESULT_SUCCESS);
108 $result->setMessage('Successfully deleted events');
109 $result->setData(
110 [
111 Entities::EVENT => null,
112 'deletedEvents' => $deletedEvents
113 ]
114 );
115
116 return $result;
117 }
118 }
119