Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 67 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| tao_actions_TaskQueueData | |
0.00% |
0 / 67 |
|
0.00% |
0 / 4 |
156 | |
0.00% |
0 / 1 |
| getTasks | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| getStatus | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
6 | |||
| archiveTask | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
20 | |||
| downloadTask | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
30 | |||
| 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; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | use oat\oatbox\reporting\Report; |
| 23 | use oat\tao\model\TaskQueueActionTrait; |
| 24 | use oat\oatbox\task\Queue; |
| 25 | use oat\oatbox\task\Task; |
| 26 | use oat\oatbox\filesystem\FileSystemService; |
| 27 | |
| 28 | /** |
| 29 | * Rest API controller for task queue |
| 30 | * |
| 31 | * @deprecated since version 21.7.0, to be removed in 22.0. Use \tao_actions_TaskQueueWebApi instead. |
| 32 | * |
| 33 | * @author GARCIA Christophe <christophe.garcia@taotesting.com> |
| 34 | */ |
| 35 | class tao_actions_TaskQueueData extends \tao_actions_CommonModule |
| 36 | { |
| 37 | use TaskQueueActionTrait; |
| 38 | |
| 39 | public function getTasks() |
| 40 | { |
| 41 | $user = $this->getSession()->getUser(); |
| 42 | |
| 43 | $taskQueue = $this->getServiceLocator()->get(Queue::SERVICE_ID); |
| 44 | |
| 45 | $dataPayLoad = $taskQueue->getPayload($user->getIdentifier()); |
| 46 | |
| 47 | $this->returnJson($dataPayLoad); |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | public function getStatus() |
| 52 | { |
| 53 | if ($this->hasRequestParameter('taskId')) { |
| 54 | /** |
| 55 | * @var $task \oat\Taskqueue\JsonTask |
| 56 | */ |
| 57 | $task = $this->getTask($this->getRequestParameter('taskId')); |
| 58 | $report = $task->getReport(); |
| 59 | $data = [ |
| 60 | 'status' => $task->getStatus(), |
| 61 | 'label' => $task->getLabel(), |
| 62 | 'creationDate' => $task->getCreationDate(), |
| 63 | 'report' => $report |
| 64 | ]; |
| 65 | $this->returnJson([ |
| 66 | 'success' => true, |
| 67 | 'data' => $data, |
| 68 | ]); |
| 69 | return; |
| 70 | } |
| 71 | $this->returnJson([ |
| 72 | 'success' => false, |
| 73 | ]); |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | public function archiveTask() |
| 78 | { |
| 79 | $taskId = $this->getRequestParameter('taskId'); |
| 80 | /** |
| 81 | * @var $taskService Queue |
| 82 | */ |
| 83 | $taskService = $this->getServiceLocator()->get(Queue::SERVICE_ID); |
| 84 | try { |
| 85 | $task = $this->getTask($taskId); |
| 86 | } catch (\Exception $e) { |
| 87 | $this->returnError(__('unkown task id %s', $taskId)); |
| 88 | return; |
| 89 | } |
| 90 | if (empty($task)) { |
| 91 | $this->returnError(__('unkown task id %s', $taskId)); |
| 92 | return; |
| 93 | } |
| 94 | try { |
| 95 | $taskService->updateTaskStatus($taskId, Task::STATUS_ARCHIVED); |
| 96 | $task = $taskService->getTask($taskId); |
| 97 | ; |
| 98 | $this->returnJson([ |
| 99 | 'success' => true , |
| 100 | 'data' => [ |
| 101 | 'id' => $taskId, |
| 102 | 'status' => $task->getStatus() |
| 103 | ] |
| 104 | ]); |
| 105 | return; |
| 106 | } catch (\Exception $e) { |
| 107 | $this->returnError(__('impossible to update task status')); |
| 108 | return; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | public function downloadTask() |
| 113 | { |
| 114 | if ($this->hasRequestParameter('taskId')) { |
| 115 | $task = $this->getTask($this->getRequestParameter('taskId')); |
| 116 | $report = $task->getReport(); |
| 117 | $report = Report::jsonUnserialize($report); |
| 118 | |
| 119 | if (!is_null($report)) { |
| 120 | $filename = ''; |
| 121 | /** @var \common_report_Report $success */ |
| 122 | foreach ($report->getSuccesses() as $success) { |
| 123 | if (!is_null($filename = $success->getData())) { |
| 124 | break; |
| 125 | } |
| 126 | } |
| 127 | /** @var FileSystemService $fileSystem */ |
| 128 | $fileSystem = $this->getServiceLocator()->get(FileSystemService::SERVICE_ID); |
| 129 | $directory = $fileSystem->getDirectory('taskQueueStorage'); |
| 130 | $file = $directory->getFile($filename); |
| 131 | header('Set-Cookie: fileDownload=true'); |
| 132 | setcookie('fileDownload', 'true', 0, '/'); |
| 133 | |
| 134 | //file meta |
| 135 | header('Content-Disposition: attachment; filename="' . $filename . '"'); |
| 136 | header('Content-Type: ' . $file->getMimeType()); |
| 137 | |
| 138 | tao_helpers_Http::returnStream($file->readPsrStream()); |
| 139 | return; |
| 140 | } |
| 141 | } |
| 142 | $this->returnJson([ |
| 143 | 'success' => false, |
| 144 | ]); |
| 145 | return; |
| 146 | } |
| 147 | } |