From da4d3eafef32cb41ac2ab3ad3bc5a021d63ad328 Mon Sep 17 00:00:00 2001 From: MCJ Vasseur <14887731+vmcj@users.noreply.github.com> Date: Sat, 30 Sep 2023 00:00:48 +0200 Subject: [PATCH] Allow reimporting existing contests --- webapp/src/Service/ImportExportService.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/webapp/src/Service/ImportExportService.php b/webapp/src/Service/ImportExportService.php index addb369a18..e16de82ac5 100644 --- a/webapp/src/Service/ImportExportService.php +++ b/webapp/src/Service/ImportExportService.php @@ -194,14 +194,15 @@ public function importContestData(mixed $data, ?string &$errorMessage = null, st return false; } - $contest = new Contest(); + $newShortNameAndExternalId = preg_replace(preg_replace( + $invalid_regex, + '_', + $data['short_name'] ?? $data['shortname'] ?? $data['short-name'] ?? $data['id'] + ); + $contest = $this->em->getRepository(Contest::class)->findOneBy(['externalid' => $newShortNameAndExternalId]) ?: new Contest(); $contest ->setName($data['name'] ?? $data['formal_name'] ) - ->setShortname(preg_replace( - $invalid_regex, - '_', - $data['short_name'] ?? $data['shortname'] ?? $data['short-name'] ?? $data['id'] - )) + ->setShortname($newShortNameAndExternalId) ->setExternalid($contest->getShortname()) ->setWarningMessage($data['warning-message'] ?? null) ->setStarttimeString(date_format($startTime, 'Y-m-d H:i:s e'))