Skip to content

Commit 8ffa050

Browse files
committed
Revert "Check if there would be any attachments/samples in the contest samples.zip"
This reverts commit d83c09eac76fecd52841e6d8d8c3eec74ee8fe95.
1 parent f4b3708 commit 8ffa050

File tree

1 file changed

+10
-43
lines changed

1 file changed

+10
-43
lines changed

webapp/src/Service/DOMJudgeService.php

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ public function getSamplesZipContent(ContestProblem $contestProblem): string
830830
return $zipFileContents;
831831
}
832832

833-
protected function addSamplesToZip(?ZipArchive $zip, ContestProblem $problem, ?string $directory = null, bool $fullZip = true): bool
833+
protected function addSamplesToZip(ZipArchive $zip, ContestProblem $problem, ?string $directory = null): void
834834
{
835835
/** @var Testcase[] $testcases */
836836
$testcases = $this->em->createQueryBuilder()
@@ -849,9 +849,6 @@ protected function addSamplesToZip(?ZipArchive $zip, ContestProblem $problem, ?s
849849
->getResult();
850850

851851
foreach ($testcases as $index => $testcase) {
852-
if (!$fullZip) {
853-
return true;
854-
}
855852
foreach (['input', 'output'] as $type) {
856853
$extension = Testcase::EXTENSION_MAPPING[$type];
857854

@@ -873,7 +870,6 @@ protected function addSamplesToZip(?ZipArchive $zip, ContestProblem $problem, ?s
873870
$zip->addFromString($filename, $content);
874871
}
875872
}
876-
return false;
877873
}
878874

879875
public function getSamplesZipStreamedResponse(ContestProblem $contestProblem): StreamedResponse
@@ -883,7 +879,7 @@ public function getSamplesZipStreamedResponse(ContestProblem $contestProblem): S
883879
return Utils::streamAsBinaryFile($zipFileContent, $outputFilename, 'zip');
884880
}
885881

886-
public function helperSamplesZipForContest(Contest $contest, bool $fullZip): StreamedResponse|bool
882+
public function getSamplesZipForContest(Contest $contest): StreamedResponse
887883
{
888884
// Note, we reload the contest with the problems and attachments, to reduce the number of queries
889885
// We do not load the testcases here since addSamplesToZip loads them
@@ -900,42 +896,30 @@ public function helperSamplesZipForContest(Contest $contest, bool $fullZip): Str
900896
->getQuery()
901897
->getSingleResult();
902898

903-
$zip = null;
904-
if ($fullZip) {
905-
$zip = new ZipArchive();
906-
if (!($tempFilename = tempnam($this->getDomjudgeTmpDir(), "export-"))) {
907-
throw new ServiceUnavailableHttpException(null, 'Could not create temporary file.');
908-
}
899+
$zip = new ZipArchive();
900+
if (!($tempFilename = tempnam($this->getDomjudgeTmpDir(), "export-"))) {
901+
throw new ServiceUnavailableHttpException(null, 'Could not create temporary file.');
902+
}
909903

910-
$res = $zip->open($tempFilename, ZipArchive::OVERWRITE);
911-
if ($res !== true) {
912-
throw new ServiceUnavailableHttpException(null, 'Could not create temporary zip file.');
913-
}
904+
$res = $zip->open($tempFilename, ZipArchive::OVERWRITE);
905+
if ($res !== true) {
906+
throw new ServiceUnavailableHttpException(null, 'Could not create temporary zip file.');
914907
}
915908

916909
/** @var ContestProblem $problem */
917910
foreach ($contest->getProblems() as $problem) {
918911
// We don't include the samples for interactive problems.
919912
if (!$problem->getProblem()->isInteractiveProblem()) {
920-
$samplesFound = $this->addSamplesToZip($zip, $problem, $problem->getShortname(), fullZip: $fullZip);;
921-
if (!$fullZip && $samplesFound) {
922-
return true;
923-
}
913+
$this->addSamplesToZip($zip, $problem, $problem->getShortname());
924914
}
925915

926916
if ($problem->getProblem()->getProblemstatementType()) {
927-
if (!$fullZip) {
928-
return true;
929-
}
930917
$filename = sprintf('%s/statement.%s', $problem->getShortname(), $problem->getProblem()->getProblemstatementType());
931918
$zip->addFromString($filename, $problem->getProblem()->getProblemstatement());
932919
}
933920

934921
/** @var ProblemAttachment $attachment */
935922
foreach ($problem->getProblem()->getAttachments() as $attachment) {
936-
if (!$fullZip) {
937-
return true;
938-
}
939923
$filename = sprintf('%s/attachments/%s', $problem->getShortname(), $attachment->getName());
940924
$zip->addFromString($filename, $attachment->getContent()->getContent());
941925
if ($attachment->getContent()->isExecutable()) {
@@ -950,34 +934,17 @@ public function helperSamplesZipForContest(Contest $contest, bool $fullZip): Str
950934
}
951935

952936
if ($contest->getContestProblemsetType()) {
953-
if (!$fullZip) {
954-
return true;
955-
}
956937
$filename = sprintf('contest.%s', $contest->getContestProblemsetType());
957938
$zip->addFromString($filename, $contest->getContestProblemset());
958939
}
959940

960-
if (!$fullZip) {
961-
return false;
962-
}
963-
964941
$zip->close();
965942
$zipFileContents = file_get_contents($tempFilename);
966943
unlink($tempFilename);
967944

968945
return Utils::streamAsBinaryFile($zipFileContents, 'samples.zip', 'zip');
969946
}
970947

971-
public function checkIfSamplesZipForContest(Contest $contest): bool
972-
{
973-
return self::helperSamplesZipForContest($contest, fullZip: false);
974-
}
975-
976-
public function getSamplesZipForContest(Contest $contest): StreamedResponse
977-
{
978-
return self::helperSamplesZipForContest($contest, fullZip: true);
979-
}
980-
981948
/**
982949
* @throws NonUniqueResultException
983950
*/

0 commit comments

Comments
 (0)