getDeliveryExecution(); return $this->addIndex($deliveryExecution); } /** * @param TestChangedEvent $event * @return \common_report_Report * @throws \common_exception_NotFound */ public function catchTestChangedEvent(TestChangedEvent $event) { $sessionMemento = $event->getSessionMemento(); $session = $event->getSession(); if ($sessionMemento && $session->getState() !== $sessionMemento->getState()) { $deliveryExecution = ServiceProxy::singleton()->getDeliveryExecution($event->getServiceCallId()); return $this->addIndex($deliveryExecution); } } /** * @param DeliveryExecutionInterface $deliveryExecution * @return \common_report_Report * @throws \common_exception_NotFound */ protected function addIndex(DeliveryExecutionInterface $deliveryExecution) { /** @var Search $searchService */ $report = \common_report_Report::createSuccess(); $searchService = $this->getServiceLocator()->get(Search::SERVICE_ID); if ($searchService->supportCustomIndex() && $this->getAdvancedSearchChecker()->isEnabled()) { $deliveryExecutionId = $deliveryExecution->getIdentifier(); $user = $this->getUserService()->getUser($deliveryExecution->getUserIdentifier()); $customFieldService = $this->getServiceLocator()->get(ResultCustomFieldsService::SERVICE_ID); $customBody = $customFieldService->getCustomFields($deliveryExecution); $body = [ 'label' => $deliveryExecution->getLabel(), self::INDEX_DELIVERY => $deliveryExecution->getDelivery()->getUri(), 'type' => ResultService::DELIVERY_RESULT_CLASS_URI, self::INDEX_TEST_TAKER => $user->getIdentifier(), self::INDEX_TEST_TAKER_FIRST_NAME => UserHelper::getUserFirstName($user, true), self::INDEX_TEST_TAKER_LAST_NAME => UserHelper::getUserLastName($user, true), self::INDEX_TEST_TAKER_NAME => UserHelper::getUserName($user, true), self::INDEX_TEST_TAKER_LABEL => UserHelper::getUserLabel($user), self::INDEX_DELIVERY_EXECUTION => $deliveryExecutionId, self::INDEX_DELIVERY_EXECUTION_START_TIME => $this->transformDateTime( $deliveryExecution->getStartTime() ) ]; $body = array_merge($body, $customBody); $queueDispatcher = $this->getServiceLocator()->get(QueueDispatcherInterface::SERVICE_ID); $queueDispatcher->createTask( new AddSearchIndexFromArray(), [$deliveryExecutionId, $body], __('Adding/Updating search index for %s', $deliveryExecution->getLabel()) ); } return $report; } /** * Control filtering visibility * @return boolean */ public function isResultSearchEnabled() { return (bool)$this->getOption(self::OPTION_RESULT_SEARCH_FIELD_VISIBILITY); } private function transformDateTime(string $getStartTime): string { $timeArray = explode(" ", $getStartTime); $date = DateTimeImmutable::createFromFormat('U', $timeArray[1]); if ($date === false) { $date = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $getStartTime); } if (!$date instanceof DateTimeImmutable) { $this->logCritical( sprintf('We were not able to transform string: "%s" delivery-execution start time!', $getStartTime) ); return ''; } return $date->format('m/d/Y H:i:s'); } private function getAdvancedSearchChecker(): AdvancedSearchChecker { return $this->getServiceLocator()->get(AdvancedSearchChecker::class); } private function getUserService(): UserService { return $this->getServiceLocator()->get(UserService::SERVICE_ID); } }