Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
10 / 10 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
MediaRelationListener | |
100.00% |
10 / 10 |
|
100.00% |
5 / 5 |
6 | |
100.00% |
1 / 1 |
whenItemIsUpdated | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
whenItemIsRemoved | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
whenMediaIsRemoved | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
whenMediaIsSaved | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
process | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 |
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) 2020 (original work) Open Assessment Technologies SA; |
19 | */ |
20 | |
21 | declare(strict_types=1); |
22 | |
23 | namespace oat\taoMediaManager\model\relation\event; |
24 | |
25 | use oat\oatbox\event\Event; |
26 | use oat\oatbox\log\LoggerAwareTrait; |
27 | use oat\oatbox\service\ConfigurableService; |
28 | use oat\taoMediaManager\model\relation\event\processor\ItemRemovedEventProcessor; |
29 | use oat\taoMediaManager\model\relation\event\processor\ItemUpdatedEventProcessor; |
30 | use oat\taoMediaManager\model\relation\event\processor\MediaRemovedEventProcessor; |
31 | use oat\taoMediaManager\model\relation\event\processor\EventProcessorInterface; |
32 | use oat\taoMediaManager\model\relation\event\processor\MediaSavedEventProcessor; |
33 | use Throwable; |
34 | |
35 | class MediaRelationListener extends ConfigurableService |
36 | { |
37 | use LoggerAwareTrait; |
38 | |
39 | public function whenItemIsUpdated(Event $event): void |
40 | { |
41 | $this->process(ItemUpdatedEventProcessor::class, $event); |
42 | } |
43 | |
44 | public function whenItemIsRemoved(Event $event): void |
45 | { |
46 | $this->process(ItemRemovedEventProcessor::class, $event); |
47 | } |
48 | |
49 | public function whenMediaIsRemoved(Event $event): void |
50 | { |
51 | $this->process(MediaRemovedEventProcessor::class, $event); |
52 | } |
53 | |
54 | public function whenMediaIsSaved(Event $event): void |
55 | { |
56 | $this->process(MediaSavedEventProcessor::class, $event); |
57 | } |
58 | |
59 | private function process(string $processor, Event $event): void |
60 | { |
61 | try { |
62 | $this->logDebug(sprintf('Processing event %s', get_class($event))); |
63 | |
64 | /** @var EventProcessorInterface $processor */ |
65 | $processor = $this->getServiceLocator()->get($processor); |
66 | $processor->process($event); |
67 | |
68 | $this->logDebug(sprintf('Event %s processed', get_class($event))); |
69 | } catch (Throwable $exception) { |
70 | $this->logError(sprintf('Error processing event %s: %s', get_class($event), $exception->getMessage())); |
71 | } |
72 | } |
73 | } |