* @package oat\tao\model\search\tasks */ class AddSearchIndexFromResource 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(); } $resource = new \core_kernel_classes_Resource(array_shift($params)); /** @var IndexService $indexService */ $indexService = $this->getServiceLocator()->get(IndexService::SERVICE_ID); $report = new \common_report_Report(\common_report_Report::TYPE_SUCCESS, __('Adding search index for %s', $resource->getUri())); try { $document = $indexService->createDocumentFromResource($resource); $this->getServiceLocator()->get(Search::SERVICE_ID)->index($document); } catch (\Exception $e) { $report->add(new \common_report_Report(\common_report_Report::TYPE_ERROR, __('Error adding search index for %s with message %s', $resource->getUri(), $e->getMessage()))); } return $report; } }