|
8 | 8 | use App\Entity\DebugPackage; |
9 | 9 | use App\Entity\Executable; |
10 | 10 | use App\Entity\ExecutableFile; |
| 11 | +use App\Entity\GenericTask; |
| 12 | +use App\Entity\GenericTaskOutput; |
11 | 13 | use App\Entity\InternalError; |
12 | 14 | use App\Entity\Judgehost; |
13 | 15 | use App\Entity\JudgeTask; |
@@ -553,6 +555,63 @@ public function addDebugInfo( |
553 | 555 | $this->em->flush(); |
554 | 556 | } |
555 | 557 |
|
| 558 | + /** |
| 559 | + * Add generic task output. |
| 560 | + */ |
| 561 | + #[IsGranted('ROLE_JUDGEHOST')] |
| 562 | + #[Rest\Post('/add-generic-task/{hostname}/{judgeTaskId<\d+>}')] |
| 563 | + #[OA\Response(response: 200, description: 'When the task output has been added')] |
| 564 | + public function addGenericTaskOutput( |
| 565 | + Request $request, |
| 566 | + #[OA\PathParameter(description: 'The hostname of the judgehost that wants to add the task output')] |
| 567 | + string $hostname, |
| 568 | + #[OA\PathParameter(description: 'The ID of the judgetask to add', schema: new OA\Schema(type: 'integer'))] |
| 569 | + int $judgeTaskId |
| 570 | + ): void { |
| 571 | + $judgeTask = $this->em->getRepository(JudgeTask::class)->find($judgeTaskId); |
| 572 | + if ($judgeTask === null) { |
| 573 | + throw new BadRequestHttpException( |
| 574 | + 'Inconsistent data, no judgetask known with judgetaskid = ' . $judgeTaskId . '.'); |
| 575 | + } |
| 576 | + |
| 577 | + $required = ['generic_task']; |
| 578 | + foreach ($required as $argument) { |
| 579 | + if (!$request->request->has($argument)) { |
| 580 | + throw new BadRequestHttpException( |
| 581 | + sprintf("Argument '%s' is mandatory", $argument)); |
| 582 | + } |
| 583 | + } |
| 584 | + |
| 585 | + $judgehost = $this->em->getRepository(Judgehost::class)->findOneBy(['hostname' => $hostname]); |
| 586 | + if (!$judgehost) { |
| 587 | + throw new BadRequestHttpException("Who are you and why are you sending us any data?"); |
| 588 | + } |
| 589 | + |
| 590 | + $genericTask = $judgeTask->getGenericTasks(); |
| 591 | + if (count($genericTask) === 0) { |
| 592 | + $genericTask = new GenericTask(); |
| 593 | + $genericTask |
| 594 | + ->setJudgeTask($judgeTask) |
| 595 | + ->setStarttime($judgeTask->getStarttime()) |
| 596 | + ->setEndtime(Utils::now()); |
| 597 | + $genericTaskOutput = new GenericTaskOutput(); |
| 598 | + $genericTaskOutput->setGenericTask($genericTask); |
| 599 | + $genericTask->setOutput($genericTaskOutput); |
| 600 | + $this->em->persist($genericTask); |
| 601 | + $this->em->persist($genericTaskOutput); |
| 602 | + } elseif (count($genercTasks) !== 1) { |
| 603 | + throw new BadRequestHttpException("There should be only one generic task for this judgetask."); |
| 604 | + } else { |
| 605 | + $genericTask = $genericTask->first(); |
| 606 | + } |
| 607 | + |
| 608 | + $genericTask->setEndtime(Utils::now()); |
| 609 | + $outputTask = base64_decode($request->request->get('generic_task')); |
| 610 | + $genericTaskOutput = $genericTask->getOutput(); |
| 611 | + $genericTaskOutput->setOutputTask($outputTask); |
| 612 | + $this->em->flush(); |
| 613 | + } |
| 614 | + |
556 | 615 | /** |
557 | 616 | * Add one JudgingRun. When relevant, finalize the judging. |
558 | 617 | * @throws DBALException |
@@ -1238,7 +1297,7 @@ public function getFilesAction( |
1238 | 1297 | return match ($type) { |
1239 | 1298 | 'source' => $this->getSourceFiles($id), |
1240 | 1299 | 'testcase' => $this->getTestcaseFiles($id), |
1241 | | - 'compare', 'compile', 'debug', 'run' => $this->getExecutableFiles($id), |
| 1300 | + 'compare', 'compile', 'debug', 'run', 'generic_task' => $this->getExecutableFiles($id), |
1242 | 1301 | default => throw new BadRequestHttpException('Unknown type requested.'), |
1243 | 1302 | }; |
1244 | 1303 | } |
|
0 commit comments