* @package oat\tao\model\search\tasks */ class DeleteSearchIndex implements Action, ServiceLocatorAwareInterface, TaskAwareInterface { use ServiceLocatorAwareTrait; use OntologyAwareTrait; use TaskAwareTrait; /** * @param $params * @return \common_report_Report * @throws \common_exception_Error * @throws \common_exception_MissingParameter */ public function __invoke($params) { if (count($params) != 1) { throw new \common_exception_MissingParameter(); } $resourceId = array_shift($params); $report = new \common_report_Report(\common_report_Report::TYPE_SUCCESS, __('Deleting search index for %s', $resourceId)); $subReport = $this->deleteIndex($resourceId); $report->add($subReport); return $report; } /** * @param $resourceId * @return \common_report_Report */ protected function deleteIndex($resourceId) { try { $this->getServiceLocator()->get(Search::SERVICE_ID)->remove($resourceId); $report = new \common_report_Report(\common_report_Report::TYPE_SUCCESS, __('Index has been deleted for %s', $resourceId)); } catch (\Exception $e) { $report = new \common_report_Report(\common_report_Report::TYPE_ERROR, __('Failed to delete index for %s', $resourceId)); } return $report; } }