getTask($taskId); $result['id'] = $this->getTaskId($task); $result['status'] = $this->getTaskStatus($task); $result['report'] = $this->getTaskReport($task); return $result; } /** * Get task instance from queue by identifier * @param $taskId task identifier * @throws \common_exception_NotFound * @return Task */ protected function getTask($taskId) { if (!isset($this->tasks[$taskId])) { /** @var Queue $taskQueue */ $taskQueue = $this->getServiceManager()->get(Queue::SERVICE_ID); $task = $taskQueue->getTask($taskId); if ($task === null) { throw new \common_exception_NotFound(__('Task not found')); } $this->tasks[$taskId] = $task; } return $this->tasks[$taskId]; } /** * Return task report. Method may be overridden to comply special format of report * @param Task $task * @return null */ protected function getTaskReport(Task $task) { return $task->getReport(); } /** * Return task status * @param Task $task * @return null */ protected function getTaskStatus(Task $task) { return $task->getStatus(); } /** * Return task identifier * @param Task $task * @return null */ protected function getTaskId(Task $task) { return $task->getId(); } /** * @param $report * @return array */ protected function getPlainReport(\common_report_Report $report) { $result = []; $result[] = $report; if ($report->hasChildren()) { foreach ($report as $r) { $result = array_merge($result, $this->getPlainReport($r)); } } return $result; } }