Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
12 / 12 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
AbstractCloner | |
100.00% |
12 / 12 |
|
100.00% |
3 / 3 |
6 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
clone | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
cloneToSpecifiedTarget | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
cloneReferentForCollectivity | n/a |
0 / 0 |
n/a |
0 / 0 |
0 |
1 | <?php |
2 | |
3 | /** |
4 | * This file is part of the MADIS - RGPD Management application. |
5 | * |
6 | * @copyright Copyright (c) 2018-2019 Soluris - Solutions Numériques Territoriales Innovantes |
7 | * |
8 | * This program is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU Affero General Public License as published by |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU Affero General Public License for more details. |
17 | * |
18 | * You should have received a copy of the GNU Affero General Public License |
19 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
20 | */ |
21 | |
22 | declare(strict_types=1); |
23 | |
24 | namespace App\Domain\Admin\Cloner; |
25 | |
26 | use App\Domain\Admin\Model; |
27 | use App\Domain\User\Model as UserModel; |
28 | use Doctrine\ORM\EntityManagerInterface; |
29 | |
30 | abstract class AbstractCloner implements ClonerInterface |
31 | { |
32 | /** |
33 | * @var EntityManagerInterface |
34 | */ |
35 | protected $entityManager; |
36 | |
37 | public function __construct(EntityManagerInterface $entityManager) |
38 | { |
39 | $this->entityManager = $entityManager; |
40 | } |
41 | |
42 | public function clone(Model\Duplication $duplication): void |
43 | { |
44 | foreach ($duplication->getTargetCollectivities() as $targetCollectivity) { |
45 | foreach ($duplication->getData() as $data) { |
46 | $clonedData = $this->cloneReferentForCollectivity($data, $targetCollectivity); |
47 | $this->entityManager->persist($clonedData); |
48 | } |
49 | } |
50 | |
51 | $this->entityManager->flush(); |
52 | } |
53 | |
54 | public function cloneToSpecifiedTarget(Model\Duplication $duplication, UserModel\Collectivity $targetCollectivity): void |
55 | { |
56 | foreach ($duplication->getData() as $data) { |
57 | $clonedData = $this->cloneReferentForCollectivity($data, $targetCollectivity); |
58 | $this->entityManager->persist($clonedData); |
59 | $duplicatedObject = $duplication->getDuplicatedObjectOfCollectivityAndOriginId($targetCollectivity, $data->getId()->toString()); |
60 | $duplicatedObject->setDuplicatId($clonedData->getId()->toString()); |
61 | } |
62 | |
63 | $this->entityManager->flush(); |
64 | } |
65 | |
66 | /** |
67 | * @param object $referent |
68 | * |
69 | * @return object |
70 | */ |
71 | abstract protected function cloneReferentForCollectivity($referent, UserModel\Collectivity $collectivity); |
72 | } |