Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
21 / 21 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
Timeout | |
100.00% |
21 / 21 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
process | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
3 | |||
getRequiredFields | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
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-2022 (original work) Open Assessment Technologies SA ; |
19 | */ |
20 | |
21 | namespace oat\taoQtiTest\models\runner\synchronisation\action; |
22 | |
23 | use common_exception_InconsistentData as InconsistentData; |
24 | use common_Logger; |
25 | use Exception; |
26 | use oat\taoQtiTest\model\Service\TimeoutCommand; |
27 | use oat\taoQtiTest\model\Service\TimeoutService; |
28 | use oat\taoQtiTest\models\runner\synchronisation\TestRunnerAction; |
29 | |
30 | class Timeout extends TestRunnerAction |
31 | { |
32 | /** |
33 | * Process the timeout action. |
34 | * |
35 | * Validate required fields. |
36 | * Stop/Start timer and save item state. |
37 | * Save item responses and wrap the timeout to runner service. |
38 | * Persist service context. |
39 | * Start next timer. |
40 | * |
41 | * @throws InconsistentData |
42 | */ |
43 | public function process(): array |
44 | { |
45 | $this->validate(); |
46 | |
47 | try { |
48 | if ($this->getRequestParameter('offline') === true) { |
49 | $this->setOffline(); |
50 | } |
51 | |
52 | $command = new TimeoutCommand( |
53 | $this->getServiceContext(), |
54 | $this->hasRequestParameter('start'), |
55 | $this->hasRequestParameter('late') |
56 | ); |
57 | |
58 | $this->setNavigationContextToCommand($command); |
59 | $this->setItemContextToCommand($command); |
60 | $this->setToolsStateContextToCommand($command); |
61 | |
62 | /** @var TimeoutService $timeout */ |
63 | $timeout = $this->getPsrContainer()->get(TimeoutService::class); |
64 | |
65 | $response = $timeout($command); |
66 | |
67 | return $response->toArray(); |
68 | } catch (Exception $e) { |
69 | common_Logger::e( |
70 | $e->getMessage(), |
71 | ['deliveryExecutionId' => $this->getServiceContext()->getTestExecutionUri()] |
72 | ); |
73 | return $this->getErrorResponse($e); |
74 | } |
75 | } |
76 | |
77 | protected function getRequiredFields(): array |
78 | { |
79 | return array_merge(parent::getRequiredFields(), ['scope']); |
80 | } |
81 | } |