Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
MesurementSubscriber
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
3 / 3
6
100.00% covered (success)
100.00%
1 / 1
 getSubscribedEvents
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 postUpdate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 process
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
4
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
22declare(strict_types=1);
23
24namespace App\Domain\Registry\Symfony\EventSubscriber\Doctrine;
25
26use App\Domain\Registry\Dictionary\MesurementStatusDictionary;
27use App\Domain\Registry\Model\Mesurement;
28use Doctrine\Common\EventSubscriber;
29use Doctrine\ORM\Event\LifecycleEventArgs;
30
31class MesurementSubscriber implements EventSubscriber
32{
33    public function getSubscribedEvents(): array
34    {
35        return [
36            'postUpdate',
37        ];
38    }
39
40    public function postUpdate(LifecycleEventArgs $args)
41    {
42        $this->process($args);
43    }
44
45    /**
46     * On applied check all link reponse on conformiteTraitement to mark mesurement as not seen.
47     */
48    private function process(LifecycleEventArgs $args): void
49    {
50        $object = $args->getObject();
51
52        if (!$object instanceof Mesurement) {
53            return;
54        }
55
56        $status = $object->getStatus();
57        foreach ($object->getConformiteTraitementReponses() as $reponse) {
58            if (MesurementStatusDictionary::STATUS_APPLIED === $status) {
59                $reponse->addActionProtectionsPlanifiedNotSeen($object);
60                $reponse->removeActionProtection($object);
61            } else {
62                $reponse->removeActionProtectionsPlanifiedNotSeen($object);
63            }
64            $args->getObjectManager()->persist($reponse);
65        }
66
67        $args->getObjectManager()->flush();
68    }
69}