Skip to content

Commit 6bb3cbe

Browse files
authored
Merge branch 'wfluxor' into mobilefriendly
2 parents de0068c + 87fab52 commit 6bb3cbe

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

webapp/src/Service/ImportExportService.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,15 @@ public function importContestData(mixed $data, ?string &$errorMessage = null, st
200200
return false;
201201
}
202202

203-
$contest = new Contest();
203+
$newShortNameAndExternalId = preg_replace(
204+
$invalid_regex,
205+
'_',
206+
$data['short_name'] ?? $data['shortname'] ?? $data['short-name'] ?? $data['id']
207+
);
208+
$contest = $this->em->getRepository(Contest::class)->findOneBy(['externalid' => $newShortNameAndExternalId]) ?: new Contest();
204209
$contest
205210
->setName($data['name'] ?? $data['formal_name'] )
206-
->setShortname(preg_replace(
207-
$invalid_regex,
208-
'_',
209-
$data['short_name'] ?? $data['shortname'] ?? $data['short-name'] ?? $data['id']
210-
))
211+
->setShortname($newShortNameAndExternalId)
211212
->setExternalid($contest->getShortname())
212213
->setWarningMessage($data['warning_message'] ?? $data['warning-message'] ?? null)
213214
->setStarttimeString(date_format($startTime, 'Y-m-d H:i:s e'))
@@ -321,18 +322,19 @@ public function importProblemsData(Contest $contest, array $problems, array &$id
321322
foreach ($problems as $problemData) {
322323
// Deal with obsolete attribute names. Also for name fall back to ID if it is not specified.
323324
$problemName = $problemData['name'] ?? $problemData['short-name'] ?? $problemData['id'] ?? null;
325+
$problemExternal = $problemData['id'] ?? $problemData['short-name'] ?? $problemLabel ?? null;
324326
$problemLabel = $problemData['label'] ?? $problemData['letter'] ?? null;
325327

326-
$problem = new Problem();
328+
$problem = $this->em->getRepository(Problem::class)->findOneBy(['externalid' => $problemName]) ?: new Problem();
327329
$problem
328330
->setName($problemName)
329331
->setTimelimit($problemData['time_limit'] ?? 10)
330-
->setExternalid($problemData['id'] ?? $problemData['short-name'] ?? $problemLabel ?? null);
332+
->setExternalid($problemExternal);
331333

332334
$this->em->persist($problem);
333335
$this->em->flush();
334336

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

0 commit comments

Comments
 (0)