Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 30 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| RegisterLaunchAction | |
0.00% |
0 / 30 |
|
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
| __invoke | |
0.00% |
0 / 30 |
|
0.00% |
0 / 1 |
2 | |||
| 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) 2017 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\ltiDeliveryProvider\install; |
| 23 | |
| 24 | use oat\ltiDeliveryProvider\model\metrics\ActiveLimitRestriction; |
| 25 | use oat\ltiDeliveryProvider\model\metrics\implementation\activeExecutionsMetrics; |
| 26 | use oat\oatbox\extension\AbstractAction; |
| 27 | use oat\tao\model\actionQueue\ActionQueue; |
| 28 | use oat\ltiDeliveryProvider\model\actions\GetActiveDeliveryExecution; |
| 29 | use oat\tao\model\metrics\MetricsService; |
| 30 | use oat\taoDelivery\models\classes\execution\event\DeliveryExecutionState; |
| 31 | use oat\oatbox\event\EventManager; |
| 32 | use oat\ltiDeliveryProvider\model\execution\LtiDeliveryExecutionService; |
| 33 | use oat\taoDelivery\models\classes\execution\event\DeliveryExecutionCreated; |
| 34 | |
| 35 | /** |
| 36 | * Installation action that register delivery launch action in the action queue. |
| 37 | * |
| 38 | * @author Aleh Hutnikau, <hutnikau@1pt.com> |
| 39 | */ |
| 40 | class RegisterLaunchAction extends AbstractAction |
| 41 | { |
| 42 | /** |
| 43 | * @param $params |
| 44 | * @return \common_report_Report |
| 45 | * @throws \common_Exception |
| 46 | * @throws \common_exception_Error |
| 47 | */ |
| 48 | public function __invoke($params) |
| 49 | { |
| 50 | $actionQueue = $this->getServiceManager()->get(ActionQueue::SERVICE_ID); |
| 51 | $actions = $actionQueue->getOption(ActionQueue::OPTION_ACTIONS); |
| 52 | $actions[GetActiveDeliveryExecution::class] = [ |
| 53 | 'restrictions' => [ |
| 54 | ActiveLimitRestriction::class => 0 |
| 55 | ], |
| 56 | ActionQueue::ACTION_PARAM_TTL => 3600, //one hour |
| 57 | ]; |
| 58 | $actionQueue->setOption(ActionQueue::OPTION_ACTIONS, $actions); |
| 59 | $this->getServiceManager()->register(ActionQueue::SERVICE_ID, $actionQueue); |
| 60 | |
| 61 | /** @var EventManager $eventManager */ |
| 62 | $eventManager = $this->getServiceManager()->get(EventManager::SERVICE_ID); |
| 63 | $eventManager->attach( |
| 64 | DeliveryExecutionState::class, |
| 65 | [LtiDeliveryExecutionService::SERVICE_ID, 'executionStateChanged'] |
| 66 | ); |
| 67 | $eventManager->attach( |
| 68 | DeliveryExecutionCreated::class, |
| 69 | [LtiDeliveryExecutionService::SERVICE_ID, 'executionCreated'] |
| 70 | ); |
| 71 | $this->getServiceManager()->register(EventManager::SERVICE_ID, $eventManager); |
| 72 | |
| 73 | $metricsService = $this->getServiceManager()->get(MetricsService::class); |
| 74 | $metrics = $metricsService->getOption($metricsService::OPTION_METRICS); |
| 75 | |
| 76 | $metrics[activeExecutionsMetrics::class] = new activeExecutionsMetrics([ |
| 77 | activeExecutionsMetrics::OPTION_TTL => 1, |
| 78 | activeExecutionsMetrics::OPTION_PERSISTENCE => 'cache' |
| 79 | ]); |
| 80 | |
| 81 | return new \common_report_Report( |
| 82 | \common_report_Report::TYPE_SUCCESS, |
| 83 | __('GetActiveDeliveryExecution action registered') |
| 84 | ); |
| 85 | } |
| 86 | } |