Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions webapp/src/Service/ImportExportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,9 @@ public function importAccountsJson(array $data, ?string &$message = null, ?array
*/
protected function importTeamData(array $teamData, ?string &$message, ?array &$saved = null): int
{
/** @var TeamAffiliation[] $createdAffiliations */
$createdAffiliations = [];
/** @var TeamCategory[] $createdCategories */
$createdCategories = [];
$createdTeams = [];
$updatedTeams = [];
Expand All @@ -1140,6 +1142,14 @@ protected function importTeamData(array $teamData, ?string &$message, ?array &$s
if (!empty($teamItem['team_affiliation']['shortname'])) {
// First look up if the affiliation already exists.
$teamAffiliation = $this->em->getRepository(TeamAffiliation::class)->findOneBy(['shortname' => $teamItem['team_affiliation']['shortname']]);
if (!$teamAffiliation) {
foreach ($createdAffiliations as $createdAffiliation) {
if ($createdAffiliation->getShortname() === $teamItem['team_affiliation']['shortname']) {
$teamAffiliation = $createdAffiliation;
break;
}
}
}
if (!$teamAffiliation) {
$teamAffiliation = new TeamAffiliation();
$propertyAccessor = PropertyAccess::createPropertyAccessor();
Expand All @@ -1166,6 +1176,15 @@ protected function importTeamData(array $teamData, ?string &$message, ?array &$s
}
} elseif (!empty($teamItem['team_affiliation']['externalid'])) {
$teamAffiliation = $this->em->getRepository(TeamAffiliation::class)->findOneBy(['externalid' => $teamItem['team_affiliation']['externalid']]);
if (!$teamAffiliation) {
foreach ($createdAffiliations as $createdAffiliation) {
if ($createdAffiliation->getExternalid() === $teamItem['team_affiliation']['externalid']) {
$teamAffiliation = $createdAffiliation;
break;
}
}
}

if (!$teamAffiliation) {
$teamAffiliation = new TeamAffiliation();
$teamAffiliation
Expand Down Expand Up @@ -1196,6 +1215,14 @@ protected function importTeamData(array $teamData, ?string &$message, ?array &$s

if (!empty($teamItem['team']['categoryid'])) {
$teamCategory = $this->em->getRepository(TeamCategory::class)->findOneBy(['externalid' => $teamItem['team']['categoryid']]);
if (!$teamCategory) {
foreach ($createdCategories as $createdCategory) {
if ($createdCategory->getExternalid() === $teamItem['team']['categoryid']) {
$teamCategory = $createdCategory;
break;
}
}
}
if (!$teamCategory) {
$teamCategory = new TeamCategory();
$teamCategory
Expand Down
15 changes: 15 additions & 0 deletions webapp/tests/Unit/Service/ImportExportServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ public function testImportTeamsTsv(): void
File_Version 2
11 447047 24 ¡i¡i¡ Lund University LU SWE INST-42
12 447837 25 Pleading not FAUlty Friedrich-Alexander-University Erlangen-Nuremberg FAU DEU INST-43
13 447057 24 Another team from Lund Lund University LU SWE INST-42
EOF;

$expectedTeams = [
Expand Down Expand Up @@ -710,6 +711,20 @@ public function testImportTeamsTsv(): void
'name' => 'Friedrich-Alexander-University Erlangen-Nuremberg',
'country' => 'DEU',
],
], [
'externalid' => '13',
'icpcid' => '447057',
'label' => null,
'name' => 'Another team from Lund',
'category' => [
'externalid' => '24',
],
'affiliation' => [
'externalid' => '42',
'shortname' => 'LU',
'name' => 'Lund University',
'country' => 'SWE',
],
],
];

Expand Down
Loading