Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
93.75% |
15 / 16 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| DataAccessControlChangedListener | |
93.75% |
15 / 16 |
|
0.00% |
0 / 1 |
4.00 | |
0.00% |
0 / 1 |
| handleEvent | |
93.75% |
15 / 16 |
|
0.00% |
0 / 1 |
4.00 | |||
| 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-2023 (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\OntologyAwareTrait; |
| 27 | use oat\oatbox\service\ConfigurableService; |
| 28 | use oat\tao\model\AdvancedSearch\AdvancedSearchChecker; |
| 29 | use oat\tao\model\event\DataAccessControlChangedEvent; |
| 30 | use oat\tao\model\search\tasks\UpdateDataAccessControlInIndex; |
| 31 | use oat\tao\model\taskQueue\QueueDispatcherInterface; |
| 32 | |
| 33 | class DataAccessControlChangedListener extends ConfigurableService |
| 34 | { |
| 35 | use OntologyAwareTrait; |
| 36 | |
| 37 | public const SERVICE_ID = 'tao/DataAccessControlChangedListener'; |
| 38 | |
| 39 | public function handleEvent(DataAccessControlChangedEvent $event): void |
| 40 | { |
| 41 | $this->getLogger()->debug('triggering index update on DataAccessControlChanged event'); |
| 42 | |
| 43 | if (!$this->getServiceLocator()->get(AdvancedSearchChecker::class)->isEnabled()) { |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | $taskMessage = __('Adding/updating search index for updated resource'); |
| 48 | |
| 49 | /** @noinspection PhpUnhandledExceptionInspection */ |
| 50 | $resource = $this->getResource($event->getResourceId()); |
| 51 | |
| 52 | if ($resource->isClass() && !$event->isRecursive()) { |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | $queueDispatcher = $this->getServiceLocator()->get(QueueDispatcherInterface::SERVICE_ID); |
| 57 | $queueDispatcher->createTask( |
| 58 | new UpdateDataAccessControlInIndex(), |
| 59 | [ |
| 60 | $resource->getUri(), |
| 61 | $event->getOperations('add'), |
| 62 | ], |
| 63 | $taskMessage |
| 64 | ); |
| 65 | } |
| 66 | } |