* @package oat\ltiDeliveryProvider\model\execution */ abstract class AbstractLtiDeliveryExecutionService extends ConfigurableService implements LtiDeliveryExecutionServiceInterface { const OPTION_QUEUE_PERSISTENCE = 'queue_persistence'; /** * @inheritdoc */ public function getActiveDeliveryExecution(\core_kernel_classes_Resource $delivery) { /** @var ActionQueue $actionQueue */ $actionQueue = $this->getServiceManager()->get(ActionQueue::SERVICE_ID); $action = new GetActiveDeliveryExecution($delivery); if ($actionQueue->perform($action)) { return $action->getResult(); } else { throw new \oat\tao\model\actionQueue\ActionFullException($actionQueue->getPosition($action)); } } /** * @param DeliveryExecutionState $event */ public function executionStateChanged(DeliveryExecutionState $event) { $persistence = $this->getPersistence(); if ($event->getState() === DeliveryExecution::STATE_ACTIVE) { $persistence->incr(self::class . '_' . 'active_executions'); } elseif ($event->getPreviousState() === DeliveryExecution::STATE_ACTIVE) { $persistence->decr(self::class . '_' . 'active_executions'); } } /** * @param DeliveryExecutionCreated $event * @throws */ public function executionCreated(DeliveryExecutionCreated $event) { $persistence = $this->getPersistence(); if ($event->getDeliveryExecution()->getState()->getUri() === DeliveryExecution::STATE_ACTIVE) { $persistence->incr(self::class . '_' . 'active_executions'); } $searchService = $this->getServiceLocator()->get(Search::SERVICE_ID); if ($searchService->supportCustomIndex()) { $session = \common_session_SessionManager::getSession(); if ($session instanceof TaoLtiSession) { $deliveryExecution = $event->getDeliveryExecution(); $body = [ 'label' => $deliveryExecution->getLabel(), 'delivery' => $deliveryExecution->getDelivery()->getUri(), 'type' => ResultService::DELIVERY_RESULT_CLASS_URI ]; $lunchData = $session->getLaunchData(); if ($lunchData->hasVariable(LtiLaunchData::RESOURCE_LINK_ID)) { $body[LtiLaunchData::RESOURCE_LINK_ID] = $lunchData->getVariable(LtiLaunchData::RESOURCE_LINK_ID); } } } } /** * @return \common_persistence_KeyValuePersistence */ protected function getPersistence() { $persistenceId = $this->getOption(self::OPTION_QUEUE_PERSISTENCE); return $this->getServiceManager()->get(\common_persistence_Manager::SERVICE_ID)->getPersistenceById($persistenceId); } }