Skip to content

Commit b6841e0

Browse files
Also create submission if the source is not a ZIP.
1 parent c84dbeb commit b6841e0

File tree

1 file changed

+67
-67
lines changed

1 file changed

+67
-67
lines changed

webapp/src/Service/ExternalContestSourceService.php

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ protected function importSubmission(string $entityType, ?string $eventId, string
14741474
// Check if we have a local file.
14751475
if (file_exists($zipUrl)) {
14761476
// Yes, use it directly
1477-
$zipFile = $zipUrl;
1477+
$zipFile = $zipUrl;
14781478
$shouldUnlink = false;
14791479
} else {
14801480
// No, download the ZIP file.
@@ -1516,86 +1516,86 @@ protected function importSubmission(string $entityType, ?string $eventId, string
15161516
fclose($ziphandler);
15171517
}
15181518
}
1519+
}
15191520

1520-
if ($submissionDownloadSucceeded) {
1521-
// Open the ZIP file.
1522-
$zip = new ZipArchive();
1523-
$zip->open($zipFile);
1521+
if ($submissionDownloadSucceeded && isset($zipFile, $tmpdir)) {
1522+
// Open the ZIP file.
1523+
$zip = new ZipArchive();
1524+
$zip->open($zipFile);
15241525

1525-
// Determine the files to submit.
1526-
/** @var UploadedFile[] $filesToSubmit */
1527-
$filesToSubmit = [];
1528-
for ($zipFileIdx = 0; $zipFileIdx < $zip->numFiles; $zipFileIdx++) {
1529-
$filename = $zip->getNameIndex($zipFileIdx);
1530-
$content = $zip->getFromName($filename);
1526+
// Determine the files to submit.
1527+
/** @var UploadedFile[] $filesToSubmit */
1528+
$filesToSubmit = [];
1529+
for ($zipFileIdx = 0; $zipFileIdx < $zip->numFiles; $zipFileIdx++) {
1530+
$filename = $zip->getNameIndex($zipFileIdx);
1531+
$content = $zip->getFromName($filename);
15311532

1532-
if (!($tmpSubmissionFile = tempnam($tmpdir, "submission_source_"))) {
1533-
$this->addOrUpdateWarning($eventId, $entityType, $data['id'], ExternalSourceWarning::TYPE_SUBMISSION_ERROR, [
1534-
'message' => 'Cannot create temporary file to extract ZIP contents for file ' . $filename,
1535-
]);
1536-
$submissionDownloadSucceeded = false;
1537-
continue;
1538-
}
1539-
file_put_contents($tmpSubmissionFile, $content);
1540-
$filesToSubmit[] = new UploadedFile(
1541-
$tmpSubmissionFile, $filename,
1542-
null, null, true
1543-
);
1533+
if (!($tmpSubmissionFile = tempnam($tmpdir, "submission_source_"))) {
1534+
$this->addOrUpdateWarning($eventId, $entityType, $data['id'], ExternalSourceWarning::TYPE_SUBMISSION_ERROR, [
1535+
'message' => 'Cannot create temporary file to extract ZIP contents for file ' . $filename,
1536+
]);
1537+
$submissionDownloadSucceeded = false;
1538+
continue;
15441539
}
1545-
} else {
1546-
$filesToSubmit = [];
1540+
file_put_contents($tmpSubmissionFile, $content);
1541+
$filesToSubmit[] = new UploadedFile(
1542+
$tmpSubmissionFile, $filename,
1543+
null, null, true
1544+
);
15471545
}
1546+
} else {
1547+
$filesToSubmit = [];
1548+
}
15481549

1549-
// If the language requires an entry point but we do not have one, use automatic entry point detection.
1550-
if ($language->getRequireEntryPoint() && $entryPoint === null) {
1551-
$entryPoint = '__auto__';
1552-
}
1550+
// If the language requires an entry point but we do not have one, use automatic entry point detection.
1551+
if ($language->getRequireEntryPoint() && $entryPoint === null) {
1552+
$entryPoint = '__auto__';
1553+
}
15531554

1554-
// Submit the solution
1555-
$contest = $this->em->getRepository(Contest::class)->find($this->getSourceContestId());
1556-
$submission = $this->submissionService->submitSolution(
1557-
team: $team,
1558-
user: null,
1559-
problem: $contestProblem,
1560-
contest: $contest,
1561-
language: $language,
1562-
files: $filesToSubmit,
1563-
source: 'shadowing',
1564-
entryPoint: $entryPoint,
1565-
externalId: $submissionId,
1566-
submitTime: $submitTime,
1567-
message: $message,
1568-
forceImportInvalid: !$submissionDownloadSucceeded
1569-
);
1570-
if (!$submission) {
1571-
$this->addOrUpdateWarning($eventId, $entityType, $data['id'], ExternalSourceWarning::TYPE_SUBMISSION_ERROR, [
1572-
'message' => 'Cannot add submission: ' . $message,
1573-
]);
1574-
// Clean up the temporary submission files.
1575-
foreach ($filesToSubmit as $file) {
1576-
unlink($file->getRealPath());
1577-
}
1578-
if (isset($zip)) {
1579-
$zip->close();
1580-
}
1581-
if ($shouldUnlink) {
1582-
unlink($zipFile);
1583-
}
1584-
return;
1555+
// Submit the solution
1556+
$contest = $this->em->getRepository(Contest::class)->find($this->getSourceContestId());
1557+
$submission = $this->submissionService->submitSolution(
1558+
team: $team,
1559+
user: null,
1560+
problem: $contestProblem,
1561+
contest: $contest,
1562+
language: $language,
1563+
files: $filesToSubmit,
1564+
source: 'shadowing',
1565+
entryPoint: $entryPoint,
1566+
externalId: $submissionId,
1567+
submitTime: $submitTime,
1568+
message: $message,
1569+
forceImportInvalid: !$submissionDownloadSucceeded
1570+
);
1571+
if (!$submission) {
1572+
$this->addOrUpdateWarning($eventId, $entityType, $data['id'], ExternalSourceWarning::TYPE_SUBMISSION_ERROR, [
1573+
'message' => 'Cannot add submission: ' . $message,
1574+
]);
1575+
// Clean up the temporary submission files.
1576+
foreach ($filesToSubmit as $file) {
1577+
unlink($file->getRealPath());
15851578
}
1586-
1587-
// Clean up the ZIP.
15881579
if (isset($zip)) {
15891580
$zip->close();
15901581
}
1591-
if ($shouldUnlink) {
1582+
if (isset($shouldUnlink) && $shouldUnlink && isset($zipFile)) {
15921583
unlink($zipFile);
15931584
}
1585+
return;
1586+
}
15941587

1595-
// Clean up the temporary submission files.
1596-
foreach ($filesToSubmit as $file) {
1597-
unlink($file->getRealPath());
1598-
}
1588+
// Clean up the ZIP.
1589+
if (isset($zip)) {
1590+
$zip->close();
1591+
}
1592+
if (isset($shouldUnlink) && $shouldUnlink && isset($zipFile)) {
1593+
unlink($zipFile);
1594+
}
1595+
1596+
// Clean up the temporary submission files.
1597+
foreach ($filesToSubmit as $file) {
1598+
unlink($file->getRealPath());
15991599
}
16001600
}
16011601

0 commit comments

Comments
 (0)