Skip to content

Commit

Permalink
Allow setting externalContestSource for contests
Browse files Browse the repository at this point in the history
  • Loading branch information
vmcj committed Nov 5, 2023
1 parent 76f434f commit 6fb24ff
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions webapp/src/Service/ImportExportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Entity\Configuration;
use App\Entity\Contest;
use App\Entity\ContestProblem;
use App\Entity\ExternalContestSource;
use App\Entity\Problem;
use App\Entity\Role;
use App\Entity\Team;
Expand Down Expand Up @@ -251,6 +252,23 @@ public function importContestData(mixed $data, ?string &$errorMessage = null, st
}

$this->em->persist($contest);

$shadow_type = $data['shadow_type'] ?? null;
if ($shadow_type) {
$externalSource = $this->em->getRepository(ExternalContestSource::class)->findOneBy(['contest' => $contest]) ?: new ExternalContestSource();
$externalSource->setContest($contest);
foreach (['source', 'username', 'password', 'type'] as $field) {
// Overwrite the existing value if the property is defined in the data: $externalSource-setSource($data['shadow_source'])
$fieldName = 'shadow_'.$field;
$fieldFunc = 'set'.ucwords($field);
$fieldArgs = [$data[$fieldName]];
if (isset($data[$fieldName])) {
$externalSource->$fieldFunc(...$fieldArgs);
}
}
$this->em->persist($externalSource);
}

$this->em->flush();

$penaltyTime = $data['penalty_time'] ?? $data['penalty-time'] ?? $data['penalty'] ?? null;
Expand Down

0 comments on commit 6fb24ff

Please sign in to comment.