Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| AddSearchIndexFromResource | |
0.00% |
0 / 18 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
| __invoke | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
12 | |||
| getIndexDocumentBuilder | |
0.00% |
0 / 1 |
|
0.00% |
0 / 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) 2018 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | namespace oat\tao\model\search\tasks; |
| 24 | |
| 25 | use oat\oatbox\action\Action; |
| 26 | use oat\tao\model\search\index\DocumentBuilder\IndexDocumentBuilderInterface; |
| 27 | use oat\tao\model\taskQueue\Task\TaskAwareInterface; |
| 28 | use oat\tao\model\taskQueue\Task\TaskAwareTrait; |
| 29 | use Zend\ServiceManager\ServiceLocatorAwareTrait; |
| 30 | use Zend\ServiceManager\ServiceLocatorAwareInterface; |
| 31 | use oat\generis\model\OntologyAwareTrait; |
| 32 | use oat\tao\model\search\Search; |
| 33 | |
| 34 | /** |
| 35 | * Class AddSearchIndexFromResource |
| 36 | * |
| 37 | * @author Aleksej Tikhanovich <aleksej@taotesting.com> |
| 38 | * @package oat\tao\model\search\tasks |
| 39 | */ |
| 40 | class AddSearchIndexFromResource implements Action, ServiceLocatorAwareInterface, TaskAwareInterface |
| 41 | { |
| 42 | use ServiceLocatorAwareTrait; |
| 43 | use OntologyAwareTrait; |
| 44 | use TaskAwareTrait; |
| 45 | |
| 46 | /** |
| 47 | * @param $params |
| 48 | * @return \common_report_Report |
| 49 | * @throws \common_exception_Error |
| 50 | * @throws \common_exception_MissingParameter |
| 51 | */ |
| 52 | public function __invoke($params) |
| 53 | { |
| 54 | if (count($params) < 1) { |
| 55 | throw new \common_exception_MissingParameter(); |
| 56 | } |
| 57 | $resource = new \core_kernel_classes_Resource(array_shift($params)); |
| 58 | |
| 59 | $report = new \common_report_Report( |
| 60 | \common_report_Report::TYPE_SUCCESS, |
| 61 | __('Adding search index for %s', $resource->getUri()) |
| 62 | ); |
| 63 | |
| 64 | try { |
| 65 | $document = $this->getIndexDocumentBuilder()->createDocumentFromResource($resource); |
| 66 | $this->getServiceLocator()->get(Search::SERVICE_ID)->index($document); |
| 67 | } catch (\Exception $e) { |
| 68 | $report->add( |
| 69 | new \common_report_Report( |
| 70 | \common_report_Report::TYPE_ERROR, |
| 71 | __('Error adding search index for %s with message %s', $resource->getUri(), $e->getMessage()) |
| 72 | ) |
| 73 | ); |
| 74 | } |
| 75 | |
| 76 | return $report; |
| 77 | } |
| 78 | |
| 79 | private function getIndexDocumentBuilder(): IndexDocumentBuilderInterface |
| 80 | { |
| 81 | return $this->getServiceLocator()->getContainer()->get(IndexDocumentBuilderInterface::class); |
| 82 | } |
| 83 | } |