Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
80.00% |
12 / 15 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ClassPropertyRemovedListener | |
80.00% |
12 / 15 |
|
50.00% |
1 / 2 |
4.13 | |
0.00% |
0 / 1 |
| handleEvent | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
2 | |||
| handleDeletedEvent | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| 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 | |
| 22 | declare(strict_types=1); |
| 23 | |
| 24 | namespace oat\tao\model\listener; |
| 25 | |
| 26 | use oat\generis\model\data\event\ClassPropertyDeletedEvent; |
| 27 | use oat\oatbox\service\ConfigurableService; |
| 28 | use oat\tao\model\AdvancedSearch\AdvancedSearchChecker; |
| 29 | use oat\tao\model\event\ClassPropertyRemovedEvent; |
| 30 | use oat\tao\model\search\tasks\DeleteIndexProperty; |
| 31 | use oat\tao\model\taskQueue\QueueDispatcherInterface; |
| 32 | |
| 33 | class ClassPropertyRemovedListener extends ConfigurableService |
| 34 | { |
| 35 | public const SERVICE_ID = 'tao/ClassPropertyRemovedListener'; |
| 36 | |
| 37 | public function handleEvent(ClassPropertyRemovedEvent $event): void |
| 38 | { |
| 39 | if (!$this->getServiceLocator()->get(AdvancedSearchChecker::class)->isEnabled()) { |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | $taskMessage = __('Updating search index'); |
| 44 | |
| 45 | /** @var QueueDispatcherInterface $queueDispatcher */ |
| 46 | $queueDispatcher = $this->getServiceLocator()->get(QueueDispatcherInterface::SERVICE_ID); |
| 47 | $queueDispatcher->createTask( |
| 48 | new DeleteIndexProperty(), |
| 49 | [ |
| 50 | $event->getClass(), |
| 51 | $event->getPropertyName() |
| 52 | ], |
| 53 | $taskMessage |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | public function handleDeletedEvent(ClassPropertyDeletedEvent $event): void |
| 58 | { |
| 59 | foreach ($event->getProperties() as $uri) { |
| 60 | $classProperty = new \core_kernel_classes_Property($uri); |
| 61 | $classProperty->clearCachedValues(); |
| 62 | } |
| 63 | } |
| 64 | } |