Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 28 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
ListDeleter | |
0.00% |
0 / 28 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
delete | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | /** |
4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU General Public License |
6 | * as published by the Free Software Foundation; under version 2 |
7 | * of the License (non-upgradable). |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | * |
18 | * Copyright (c) 2021 (original work) Open Assessment Technologies SA. |
19 | */ |
20 | |
21 | declare(strict_types=1); |
22 | |
23 | namespace oat\taoBackOffice\model\lists\Service; |
24 | |
25 | use Throwable; |
26 | use core_kernel_classes_Class; |
27 | use oat\tao\model\Specification\ClassSpecificationInterface; |
28 | use oat\taoBackOffice\model\lists\Contract\ListDeleterInterface; |
29 | use oat\generis\model\resource\Context\ResourceRepositoryContext; |
30 | use oat\taoBackOffice\model\lists\Exception\ListDeletionException; |
31 | use oat\generis\model\resource\Contract\ResourceRepositoryInterface; |
32 | use oat\taoBackOffice\model\ListElement\Contract\ListElementsDeleterInterface; |
33 | use oat\tao\model\Lists\DataAccess\Repository\ParentPropertyListCachedRepository; |
34 | |
35 | class ListDeleter implements ListDeleterInterface |
36 | { |
37 | /** @var ListElementsDeleterInterface */ |
38 | private $listElementsDeleter; |
39 | |
40 | /** @var ClassSpecificationInterface */ |
41 | private $remoteListClassSpecification; |
42 | |
43 | /** @var ParentPropertyListCachedRepository */ |
44 | private $parentPropertyListCachedRepository; |
45 | |
46 | /** @var ResourceRepositoryInterface */ |
47 | private $classRepository; |
48 | |
49 | public function __construct( |
50 | ListElementsDeleterInterface $listElementsDeleter, |
51 | ClassSpecificationInterface $remoteListClassSpecification, |
52 | ParentPropertyListCachedRepository $parentPropertyListCachedRepository, |
53 | ResourceRepositoryInterface $classRepository |
54 | ) { |
55 | $this->listElementsDeleter = $listElementsDeleter; |
56 | $this->remoteListClassSpecification = $remoteListClassSpecification; |
57 | $this->parentPropertyListCachedRepository = $parentPropertyListCachedRepository; |
58 | $this->classRepository = $classRepository; |
59 | } |
60 | |
61 | public function delete(core_kernel_classes_Class $list): void |
62 | { |
63 | $this->listElementsDeleter->delete($list); |
64 | |
65 | if ($this->remoteListClassSpecification->isSatisfiedBy($list)) { |
66 | $this->parentPropertyListCachedRepository->deleteCache( |
67 | [ |
68 | ParentPropertyListCachedRepository::OPTION_LIST_URI => $list->getUri(), |
69 | ] |
70 | ); |
71 | } |
72 | |
73 | try { |
74 | $this->classRepository->delete( |
75 | new ResourceRepositoryContext( |
76 | [ |
77 | ResourceRepositoryContext::PARAM_CLASS => $list, |
78 | ] |
79 | ) |
80 | ); |
81 | } catch (Throwable $exception) { |
82 | throw new ListDeletionException( |
83 | sprintf( |
84 | 'Unable to delete list "%s::%s" (%s).', |
85 | $list->getLabel(), |
86 | $list->getUri(), |
87 | $exception->getMessage() |
88 | ), |
89 | __('Unable to delete the selected list') |
90 | ); |
91 | } |
92 | } |
93 | } |