PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
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 / Bookable / Service / DeleteServiceCommandHandler.php
ameliabooking / src / Application / Commands / Bookable / Service Last commit date
AddServiceCommand.php 7 years ago AddServiceCommandHandler.php 2 years ago DeleteServiceCommand.php 7 years ago DeleteServiceCommandHandler.php 2 years ago GetServiceCommand.php 7 years ago GetServiceCommandHandler.php 2 years ago GetServiceDeleteEffectCommand.php 7 years ago GetServiceDeleteEffectCommandHandler.php 2 years ago GetServicesCommand.php 7 years ago GetServicesCommandHandler.php 2 years ago UpdateServiceCommand.php 7 years ago UpdateServiceCommandHandler.php 2 years ago UpdateServiceStatusCommand.php 7 years ago UpdateServiceStatusCommandHandler.php 2 years ago UpdateServicesPositionsCommand.php 7 years ago UpdateServicesPositionsCommandHandler.php 2 years ago
DeleteServiceCommandHandler.php
93 lines
1 <?php
2 /**
3 * @copyright © TMS-Plugins. All rights reserved.
4 * @licence See LICENCE.md for license details.
5 */
6
7 namespace AmeliaBooking\Application\Commands\Bookable\Service;
8
9 use AmeliaBooking\Application\Commands\CommandHandler;
10 use AmeliaBooking\Application\Commands\CommandResult;
11 use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException;
12 use AmeliaBooking\Application\Services\Bookable\BookableApplicationService;
13 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
14 use AmeliaBooking\Domain\Entity\Bookable\Service\Service;
15 use AmeliaBooking\Domain\Entity\Entities;
16 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
17 use AmeliaBooking\Infrastructure\Repository\Bookable\Service\ServiceRepository;
18 use Interop\Container\Exception\ContainerException;
19 use Slim\Exception\ContainerValueNotFoundException;
20
21 /**
22 * Class DeleteServiceCommandHandler
23 *
24 * @package AmeliaBooking\Application\Commands\Bookable\Service
25 */
26 class DeleteServiceCommandHandler extends CommandHandler
27 {
28 /**
29 * @param DeleteServiceCommand $command
30 *
31 * @return CommandResult
32 * @throws ContainerValueNotFoundException
33 * @throws InvalidArgumentException
34 * @throws QueryExecutionException
35 * @throws AccessDeniedException
36 * @throws ContainerException
37 */
38 public function handle(DeleteServiceCommand $command)
39 {
40 if (!$command->getPermissionService()->currentUserCanDelete(Entities::SERVICES)) {
41 throw new AccessDeniedException('You are not allowed to delete services.');
42 }
43
44 $result = new CommandResult();
45
46 $this->checkMandatoryFields($command);
47
48 /** @var BookableApplicationService $bookableApplicationService */
49 $bookableApplicationService = $this->getContainer()->get('application.bookable.service');
50
51 $appointmentsCount = $bookableApplicationService->getAppointmentsCountForServices([$command->getArg('id')]);
52
53 /** @var ServiceRepository $serviceRepository */
54 $serviceRepository = $this->container->get('domain.bookable.service.repository');
55
56 /** @var Service $service */
57 $service = $serviceRepository->getByCriteria(
58 ['services' => [$command->getArg('id')]]
59 )->getItem($command->getArg('id'));
60
61 if ($appointmentsCount['futureAppointments']) {
62 $result->setResult(CommandResult::RESULT_CONFLICT);
63 $result->setMessage('Could not delete service.');
64 $result->setData([]);
65
66 return $result;
67 }
68
69 $serviceRepository->beginTransaction();
70
71 do_action('amelia_before_service_deleted', $service->toArray());
72
73 if (!$bookableApplicationService->deleteService($service)) {
74 $serviceRepository->rollback();
75
76 $result->setResult(CommandResult::RESULT_ERROR);
77 $result->setMessage('Could not delete service.');
78
79 return $result;
80 }
81
82 $serviceRepository->commit();
83
84 do_action('amelia_after_service_deleted', $service->toArray());
85
86 $result->setResult(CommandResult::RESULT_SUCCESS);
87 $result->setMessage('Successfully deleted service.');
88 $result->setData([]);
89
90 return $result;
91 }
92 }
93