*/ class tao_actions_TaskQueueData extends \tao_actions_CommonModule { use TaskQueueActionTrait; public function getTasks() { $user = $this->getSession()->getUser(); $taskQueue = $this->getServiceLocator()->get(Queue::SERVICE_ID); $dataPayLoad = $taskQueue->getPayload($user->getIdentifier()); $this->returnJson($dataPayLoad); return; } public function getStatus() { if ($this->hasRequestParameter('taskId')) { /** * @var $task \oat\Taskqueue\JsonTask */ $task = $this->getTask($this->getRequestParameter('taskId')); $report = $task->getReport(); $data = [ 'status' => $task->getStatus(), 'label' => $task->getLabel(), 'creationDate' => $task->getCreationDate(), 'report' => $report ]; $this->returnJson([ 'success' => true, 'data' => $data, ]); return; } $this->returnJson([ 'success' => false, ]); return; } public function archiveTask() { $taskId = $this->getRequestParameter('taskId'); /** * @var $taskService Queue */ $taskService = $this->getServiceLocator()->get(Queue::SERVICE_ID); try { $task = $this->getTask($taskId); } catch (\Exception $e) { $this->returnError(__('unkown task id %s', $taskId)); return; } if (empty($task)) { $this->returnError(__('unkown task id %s', $taskId)); return; } try { $taskService->updateTaskStatus($taskId, Task::STATUS_ARCHIVED); $task = $taskService->getTask($taskId); ; $this->returnJson([ 'success' => true , 'data' => [ 'id' => $taskId, 'status' => $task->getStatus() ] ]); return; } catch (\Exception $e) { $this->returnError(__('impossible to update task status')); return; } } public function downloadTask() { if ($this->hasRequestParameter('taskId')) { $task = $this->getTask($this->getRequestParameter('taskId')); $report = $task->getReport(); $report = Report::jsonUnserialize($report); if (!is_null($report)) { $filename = ''; /** @var \common_report_Report $success */ foreach ($report->getSuccesses() as $success) { if (!is_null($filename = $success->getData())) { break; } } /** @var FileSystemService $fileSystem */ $fileSystem = $this->getServiceLocator()->get(FileSystemService::SERVICE_ID); $directory = $fileSystem->getDirectory('taskQueueStorage'); $file = $directory->getFile($filename); header('Set-Cookie: fileDownload=true'); setcookie('fileDownload', 'true', 0, '/'); //file meta header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Content-Type: ' . $file->getMimeType()); tao_helpers_Http::returnStream($file->readPsrStream()); return; } } $this->returnJson([ 'success' => false, ]); return; } }