Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| TaskQueueActionTrait | |
0.00% |
0 / 21 |
|
0.00% |
0 / 6 |
110 | |
0.00% |
0 / 1 |
| getTaskData | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| getTask | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
| getTaskReport | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTaskStatus | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTaskId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getPlainReport | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| 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) 2016 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\tao\model; |
| 23 | |
| 24 | use oat\oatbox\task\Queue; |
| 25 | use oat\oatbox\task\Task; |
| 26 | |
| 27 | /** |
| 28 | * @deprecated since version 21.7.0, to be removed in 22.0. Use \oat\tao\model\taskQueue\TaskLogActionTrait instead |
| 29 | */ |
| 30 | trait TaskQueueActionTrait |
| 31 | { |
| 32 | /** |
| 33 | * @var Task[] |
| 34 | */ |
| 35 | protected $tasks = []; |
| 36 | |
| 37 | /** |
| 38 | * Template method to generate task data to be returned to the end user. |
| 39 | * @param string $taskId |
| 40 | * @return array |
| 41 | */ |
| 42 | protected function getTaskData($taskId) |
| 43 | { |
| 44 | $task = $this->getTask($taskId); |
| 45 | $result['id'] = $this->getTaskId($task); |
| 46 | $result['status'] = $this->getTaskStatus($task); |
| 47 | $result['report'] = $this->getTaskReport($task); |
| 48 | |
| 49 | return $result; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Get task instance from queue by identifier |
| 54 | * @param $taskId task identifier |
| 55 | * @throws \common_exception_NotFound |
| 56 | * @return Task |
| 57 | */ |
| 58 | protected function getTask($taskId) |
| 59 | { |
| 60 | if (!isset($this->tasks[$taskId])) { |
| 61 | /** @var Queue $taskQueue */ |
| 62 | $taskQueue = $this->getServiceManager()->get(Queue::SERVICE_ID); |
| 63 | $task = $taskQueue->getTask($taskId); |
| 64 | if ($task === null) { |
| 65 | throw new \common_exception_NotFound(__('Task not found')); |
| 66 | } |
| 67 | $this->tasks[$taskId] = $task; |
| 68 | } |
| 69 | return $this->tasks[$taskId]; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Return task report. Method may be overridden to comply special format of report |
| 74 | * @param Task $task |
| 75 | * @return null |
| 76 | */ |
| 77 | protected function getTaskReport($task) |
| 78 | { |
| 79 | return $task->getReport(); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Return task status |
| 84 | * @param Task $task |
| 85 | * @return null |
| 86 | */ |
| 87 | protected function getTaskStatus($task) |
| 88 | { |
| 89 | return $task->getStatus(); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Return task identifier |
| 94 | * @param Task $task |
| 95 | * @return null |
| 96 | */ |
| 97 | protected function getTaskId($task) |
| 98 | { |
| 99 | return $task->getId(); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * @param $report |
| 104 | * @return array |
| 105 | */ |
| 106 | protected function getPlainReport(\common_report_Report $report) |
| 107 | { |
| 108 | $result = []; |
| 109 | $result[] = $report; |
| 110 | if ($report->hasChildren()) { |
| 111 | foreach ($report as $r) { |
| 112 | $result = array_merge($result, $this->getPlainReport($r)); |
| 113 | } |
| 114 | } |
| 115 | return $result; |
| 116 | } |
| 117 | } |