Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| tao_actions_QueueAction | |
0.00% |
0 / 24 |
|
0.00% |
0 / 6 |
156 | |
0.00% |
0 / 1 |
| getQueueService | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| isAsyncQueue | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getTaskReport | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| prepareDownload | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| getReportAttachment | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
20 | |||
| getFile | |
0.00% |
0 / 3 |
|
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; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | use oat\generis\model\OntologyAwareTrait; |
| 23 | use oat\oatbox\filesystem\File; |
| 24 | use oat\oatbox\task\Task; |
| 25 | use oat\tao\model\TaskQueueActionTrait; |
| 26 | use oat\oatbox\task\Queue; |
| 27 | use oat\oatbox\task\implementation\SyncQueue; |
| 28 | |
| 29 | /** |
| 30 | * @deprecated since version 21.7.0, to be removed in 22.0. |
| 31 | */ |
| 32 | class tao_actions_QueueAction extends \tao_actions_SaSModule |
| 33 | { |
| 34 | use TaskQueueActionTrait; |
| 35 | |
| 36 | /** |
| 37 | * @var Queue |
| 38 | */ |
| 39 | protected $queueService; |
| 40 | |
| 41 | /** |
| 42 | * @return Queue |
| 43 | */ |
| 44 | protected function getQueueService() |
| 45 | { |
| 46 | if (!$this->queueService) { |
| 47 | $this->queueService = $this->getServiceLocator()->get(Queue::SERVICE_ID); |
| 48 | } |
| 49 | return $this->queueService; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Checks if the queue manager is asynchronous |
| 54 | * @return bool |
| 55 | */ |
| 56 | protected function isAsyncQueue() |
| 57 | { |
| 58 | $queue = $this->getQueueService(); |
| 59 | return !($queue instanceof SyncQueue); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * @param Task $task |
| 64 | * @return common_report_Report |
| 65 | */ |
| 66 | protected function getTaskReport($task) |
| 67 | { |
| 68 | $status = $task->getStatus(); |
| 69 | if ($status === Task::STATUS_FINISHED || $status === Task::STATUS_ARCHIVED) { |
| 70 | $report = $task->getReport(); |
| 71 | } else { |
| 72 | $report = \common_report_Report::createInfo(__('task created')); |
| 73 | } |
| 74 | return $report; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Sets the headers to download a file |
| 79 | * @param string $fileName |
| 80 | * @param string $mimeType |
| 81 | */ |
| 82 | protected function prepareDownload($fileName, $mimeType) |
| 83 | { |
| 84 | //used by jquery file download to find out the download has been triggered ... |
| 85 | header('Set-Cookie: fileDownload=true'); |
| 86 | setcookie('fileDownload', 'true', 0, '/'); |
| 87 | |
| 88 | //file meta |
| 89 | header('Content-Disposition: attachment; filename="' . $fileName . '"'); |
| 90 | header('Content-Type: ' . $mimeType); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Extracts the path of the file attached to a report |
| 95 | * @param common_report_Report $report |
| 96 | * @return mixed|null |
| 97 | */ |
| 98 | protected function getReportAttachment(common_report_Report $report) |
| 99 | { |
| 100 | $filename = null; |
| 101 | /** @var common_report_Report $success */ |
| 102 | foreach ($report->getSuccesses() as $success) { |
| 103 | if (!is_null($filename = $success->getData())) { |
| 104 | if (is_array($filename)) { |
| 105 | $filename = $filename['uriResource']; |
| 106 | } |
| 107 | break; |
| 108 | } |
| 109 | } |
| 110 | return $filename; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Gets file from URI |
| 115 | * @param string $fileUri |
| 116 | * @return File |
| 117 | */ |
| 118 | protected function getFile($fileUri) |
| 119 | { |
| 120 | /* @var \oat\oatbox\filesystem\FileSystemService $fileSystemService */ |
| 121 | $fileSystemService = $this->getServiceLocator()->get(\oat\oatbox\filesystem\FileSystemService::SERVICE_ID); |
| 122 | $storageService = $fileSystemService->getFileSystem(Queue::FILE_SYSTEM_ID); |
| 123 | |
| 124 | return $storageService->readStream($fileUri); |
| 125 | } |
| 126 | } |