AddEventCommand.php
7 years ago
AddEventCommandHandler.php
2 years ago
DeleteEventBookingCommand.php
7 years ago
DeleteEventBookingCommandHandler.php
1 year ago
DeleteEventCommand.php
7 years ago
DeleteEventCommandHandler.php
2 years ago
GetCalendarEventsCommand.php
4 years ago
GetCalendarEventsCommandHandler.php
1 year ago
GetEventBookingsCommand.php
1 year ago
GetEventBookingsCommandHandler.php
1 year ago
GetEventCommand.php
7 years ago
GetEventCommandHandler.php
1 year ago
GetEventDeleteEffectCommand.php
7 years ago
GetEventDeleteEffectCommandHandler.php
2 years ago
GetEventsCommand.php
7 years ago
GetEventsCommandHandler.php
1 year ago
UpdateEventBookingCommand.php
7 years ago
UpdateEventBookingCommandHandler.php
1 year ago
UpdateEventCommand.php
7 years ago
UpdateEventCommandHandler.php
1 year ago
UpdateEventStatusCommand.php
7 years ago
UpdateEventStatusCommandHandler.php
2 years ago
DeleteEventCommandHandler.php
85 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\Common\Exceptions\InvalidArgumentException; |
| 10 | use AmeliaBooking\Domain\Entity\Booking\Event\Event; |
| 11 | use AmeliaBooking\Domain\Entity\Entities; |
| 12 | use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException; |
| 13 | use AmeliaBooking\Infrastructure\Repository\Booking\Event\EventRepository; |
| 14 | |
| 15 | /** |
| 16 | * Class DeleteEventCommandHandler |
| 17 | * |
| 18 | * @package AmeliaBooking\Application\Commands\Booking\Event |
| 19 | */ |
| 20 | class DeleteEventCommandHandler extends CommandHandler |
| 21 | { |
| 22 | /** |
| 23 | * @var array |
| 24 | */ |
| 25 | public $mandatoryFields = [ |
| 26 | 'applyGlobally' |
| 27 | ]; |
| 28 | |
| 29 | /** |
| 30 | * @param DeleteEventCommand $command |
| 31 | * |
| 32 | * @return CommandResult |
| 33 | * @throws \Slim\Exception\ContainerValueNotFoundException |
| 34 | * @throws AccessDeniedException |
| 35 | * @throws InvalidArgumentException |
| 36 | * @throws QueryExecutionException |
| 37 | * @throws \Interop\Container\Exception\ContainerException |
| 38 | */ |
| 39 | public function handle(DeleteEventCommand $command) |
| 40 | { |
| 41 | if (!$command->getPermissionService()->currentUserCanDelete(Entities::EVENTS)) { |
| 42 | throw new AccessDeniedException('You are not allowed to delete event'); |
| 43 | } |
| 44 | |
| 45 | $result = new CommandResult(); |
| 46 | |
| 47 | $this->checkMandatoryFields($command); |
| 48 | |
| 49 | /** @var EventApplicationService $eventApplicationService */ |
| 50 | $eventApplicationService = $this->container->get('application.booking.event.service'); |
| 51 | |
| 52 | /** @var EventRepository $eventRepository */ |
| 53 | $eventRepository = $this->container->get('domain.booking.event.repository'); |
| 54 | |
| 55 | $event = $eventRepository->getById($command->getArg('id')); |
| 56 | |
| 57 | $eventRepository->beginTransaction(); |
| 58 | |
| 59 | |
| 60 | do_action('amelia_before_event_deleted', $event ? $event->toArray() : null); |
| 61 | |
| 62 | try { |
| 63 | $deletedEvents = $eventApplicationService->delete($event, $command->getField('applyGlobally')); |
| 64 | } catch (QueryExecutionException $e) { |
| 65 | $eventRepository->rollback(); |
| 66 | throw $e; |
| 67 | } |
| 68 | |
| 69 | $eventRepository->commit(); |
| 70 | |
| 71 | do_action('amelia_after_event_deleted', $event ? $event->toArray() : null); |
| 72 | |
| 73 | $result->setResult(CommandResult::RESULT_SUCCESS); |
| 74 | $result->setMessage('Successfully deleted event'); |
| 75 | $result->setData( |
| 76 | [ |
| 77 | Entities::EVENT => $event->toArray(), |
| 78 | 'deletedEvents' => $deletedEvents |
| 79 | ] |
| 80 | ); |
| 81 | |
| 82 | return $result; |
| 83 | } |
| 84 | } |
| 85 |