Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| DeleteSearchIndex | |
0.00% |
0 / 21 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
| __invoke | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| deleteIndex | |
0.00% |
0 / 11 |
|
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) 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\taskQueue\Task\TaskAwareInterface; |
| 27 | use oat\tao\model\taskQueue\Task\TaskAwareTrait; |
| 28 | use Zend\ServiceManager\ServiceLocatorAwareTrait; |
| 29 | use Zend\ServiceManager\ServiceLocatorAwareInterface; |
| 30 | use oat\generis\model\OntologyAwareTrait; |
| 31 | use oat\tao\model\search\Search; |
| 32 | |
| 33 | /** |
| 34 | * Class DeleteSearchIndex |
| 35 | * |
| 36 | * @author Aleksej Tikhanovich <aleksej@taotesting.com> |
| 37 | * @package oat\tao\model\search\tasks |
| 38 | */ |
| 39 | class DeleteSearchIndex implements Action, ServiceLocatorAwareInterface, TaskAwareInterface |
| 40 | { |
| 41 | use ServiceLocatorAwareTrait; |
| 42 | use OntologyAwareTrait; |
| 43 | use TaskAwareTrait; |
| 44 | |
| 45 | /** |
| 46 | * @param $params |
| 47 | * @return \common_report_Report |
| 48 | * @throws \common_exception_Error |
| 49 | * @throws \common_exception_MissingParameter |
| 50 | */ |
| 51 | public function __invoke($params) |
| 52 | { |
| 53 | if (count($params) != 1) { |
| 54 | throw new \common_exception_MissingParameter(); |
| 55 | } |
| 56 | $resourceId = array_shift($params); |
| 57 | $report = new \common_report_Report( |
| 58 | \common_report_Report::TYPE_SUCCESS, |
| 59 | __('Deleting search index for %s', $resourceId) |
| 60 | ); |
| 61 | $subReport = $this->deleteIndex($resourceId); |
| 62 | $report->add($subReport); |
| 63 | return $report; |
| 64 | } |
| 65 | /** |
| 66 | * @param $resourceId |
| 67 | * @return \common_report_Report |
| 68 | */ |
| 69 | protected function deleteIndex($resourceId) |
| 70 | { |
| 71 | try { |
| 72 | $this->getServiceLocator()->get(Search::SERVICE_ID)->remove($resourceId); |
| 73 | $report = new \common_report_Report( |
| 74 | \common_report_Report::TYPE_SUCCESS, |
| 75 | __('Index has been deleted for %s', $resourceId) |
| 76 | ); |
| 77 | } catch (\Exception $e) { |
| 78 | $report = new \common_report_Report( |
| 79 | \common_report_Report::TYPE_ERROR, |
| 80 | __('Failed to delete index for %s', $resourceId) |
| 81 | ); |
| 82 | } |
| 83 | return $report; |
| 84 | } |
| 85 | } |