Skip to content

Commit 87fab52

Browse files
committed
Allow reimport of contest problems
Full reimport of example problems works both in datasource={0,1}
1 parent 55958ed commit 87fab52

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

webapp/src/Service/ImportExportService.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,18 +322,19 @@ public function importProblemsData(Contest $contest, array $problems, array &$id
322322
foreach ($problems as $problemData) {
323323
// Deal with obsolete attribute names. Also for name fall back to ID if it is not specified.
324324
$problemName = $problemData['name'] ?? $problemData['short-name'] ?? $problemData['id'] ?? null;
325+
$problemExternal = $problemData['id'] ?? $problemData['short-name'] ?? $problemLabel ?? null;
325326
$problemLabel = $problemData['label'] ?? $problemData['letter'] ?? null;
326327

327-
$problem = new Problem();
328+
$problem = $this->em->getRepository(Problem::class)->findOneBy(['externalid' => $problemName]) ?: new Problem();
328329
$problem
329330
->setName($problemName)
330331
->setTimelimit($problemData['time_limit'] ?? 10)
331-
->setExternalid($problemData['id'] ?? $problemData['short-name'] ?? $problemLabel ?? null);
332+
->setExternalid($problemExternal);
332333

333334
$this->em->persist($problem);
334335
$this->em->flush();
335336

336-
$contestProblem = new ContestProblem();
337+
$contestProblem = $this->em->getRepository(ContestProblem::class)->findOneBy(['shortname' => $problemLabel, 'problem' => $problem, 'contest' => $contest]) ?: new ContestProblem();
337338
$contestProblem
338339
->setShortname($problemLabel)
339340
->setColor($problemData['rgb'] ?? $problemData['color'] ?? null)

0 commit comments

Comments
 (0)