getContainer()->getPermissionsService()->currentUserCanWrite(Entities::EVENTS)) { throw new AccessDeniedException('You are not allowed to update event'); } $result = new CommandResult(); $this->checkMandatoryFields($command); /** @var EventRepository $eventRepository */ $eventRepository = $this->container->get('domain.booking.event.repository'); /** @var EventApplicationService $eventApplicationService */ $eventApplicationService = $this->container->get('application.booking.event.service'); /** @var Event $event */ $event = EventFactory::create($command->getFields()); if (!$event instanceof Event) { $result->setResult(CommandResult::RESULT_ERROR); $result->setMessage('Could not update event'); return $result; } /** @var Event $oldEvent */ $oldEvent = $eventRepository->getById($event->getId()->getValue()); if ($oldEvent->getRecurring() && $event->getRecurring() && ( $event->getRecurring()->getUntil()->getValue() < $oldEvent->getRecurring()->getUntil()->getValue() || $event->getRecurring()->getCycle()->getValue() !== $oldEvent->getRecurring()->getCycle()->getValue() ) ) { $result->setResult(CommandResult::RESULT_ERROR); $result->setMessage('Could not update event'); return $result; } $event->setBookings($oldEvent->getBookings()); if (!$event instanceof Event) { $result->setResult(CommandResult::RESULT_ERROR); $result->setMessage('Could not update event'); return $result; } $eventRepository->beginTransaction(); try { $rescheduledEvents = $eventApplicationService->update( $oldEvent, $event, $command->getField('applyGlobally') ); } catch (QueryExecutionException $e) { $eventRepository->rollback(); throw $e; } $eventRepository->commit(); $result->setResult(CommandResult::RESULT_SUCCESS); $result->setMessage('Successfully updated event.'); $result->setData( [ Entities::EVENTS => $rescheduledEvents->toArray(), ] ); return $result; } }