Skip to content

Commit

Permalink
Move everything under a special key
Browse files Browse the repository at this point in the history
  • Loading branch information
vmcj committed Nov 6, 2023
1 parent f4485a6 commit ee0f25a
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions webapp/src/Service/ImportExportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,15 @@ public function importContestData(mixed $data, ?string &$errorMessage = null, st

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

$shadow_type = $data['shadow_type'] ?? null;
if ($shadow_type) {
$shadow = $data['shadow'] ?? null;
if ($shadow) {
$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;
// Overwrite the existing value if the property is defined in the data: $externalSource-setSource($data['shadow']['source'])
$fieldFunc = 'set'.ucwords($field);
$fieldArgs = [$data[$fieldName]];
if (isset($data[$fieldName])) {
$fieldArgs = [$shadow[$field]];
if (isset($shadow[$field])) {
$externalSource->$fieldFunc(...$fieldArgs);
}
}
Expand Down

0 comments on commit ee0f25a

Please sign in to comment.