Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| DeleteIndexProperty | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
| __invoke | |
0.00% |
0 / 24 |
|
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\search\tasks; |
| 25 | |
| 26 | use common_report_Report; |
| 27 | use core_kernel_classes_Class; |
| 28 | use oat\oatbox\action\Action; |
| 29 | use oat\oatbox\log\LoggerAwareTrait; |
| 30 | use oat\tao\model\search\index\IndexUpdaterInterface; |
| 31 | use oat\tao\model\taskQueue\Task\TaskAwareInterface; |
| 32 | use oat\tao\model\taskQueue\Task\TaskAwareTrait; |
| 33 | use Throwable; |
| 34 | use Zend\ServiceManager\ServiceLocatorAwareInterface; |
| 35 | use Zend\ServiceManager\ServiceLocatorAwareTrait; |
| 36 | |
| 37 | class DeleteIndexProperty implements Action, ServiceLocatorAwareInterface, TaskAwareInterface |
| 38 | { |
| 39 | use ServiceLocatorAwareTrait; |
| 40 | use TaskAwareTrait; |
| 41 | use LoggerAwareTrait; |
| 42 | use IndexTrait; |
| 43 | |
| 44 | public function __invoke($params): common_report_Report |
| 45 | { |
| 46 | [$class, $propertyName] = $params; |
| 47 | |
| 48 | $class = new core_kernel_classes_Class($class['uriResource']); |
| 49 | $propertyData = [ |
| 50 | 'name' => $propertyName, |
| 51 | 'type' => $class->getUri(), |
| 52 | 'parentClasses' => $this->getParentClasses($class) |
| 53 | ]; |
| 54 | |
| 55 | $this->logInfo( |
| 56 | sprintf( |
| 57 | 'Removing property "%s" with type "%s" from index', |
| 58 | $propertyName, |
| 59 | $class->getUri() |
| 60 | ) |
| 61 | ); |
| 62 | |
| 63 | try { |
| 64 | $this->getServiceLocator() |
| 65 | ->get(IndexUpdaterInterface::SERVICE_ID) |
| 66 | ->deleteProperty($propertyData); |
| 67 | } catch (Throwable $exception) { |
| 68 | $message = 'Failed to remove class property from search index'; |
| 69 | $this->logError($message); |
| 70 | |
| 71 | return common_report_Report::createFailure(__($message)); |
| 72 | } |
| 73 | |
| 74 | $message = 'Class property removed successfully.'; |
| 75 | $this->logInfo($message); |
| 76 | |
| 77 | return common_report_Report::createSuccess(__($message)); |
| 78 | } |
| 79 | } |