Compare commits

...

2 commits

Author SHA1 Message Date
ab4ebe93a3 Merge pull request 'Improves game importer' (#16) from develop into master
All checks were successful
/ build (push) Successful in 36s
Reviewed-on: #16
2024-11-08 13:49:56 +00:00
56fee01322 Improves game importer 2024-11-08 14:49:04 +01:00

View file

@ -83,6 +83,9 @@ final class GameImporter
$totalRows = 0; $totalRows = 0;
$addedAmount = 0; $addedAmount = 0;
$foundGames = [];
$rowValues = [];
foreach ($worksheet->getRowIterator(self::HEADER_ROW_INDEX + 1) as $row) { foreach ($worksheet->getRowIterator(self::HEADER_ROW_INDEX + 1) as $row) {
$totalRows++; $totalRows++;
@ -96,7 +99,8 @@ final class GameImporter
foreach ($columnDefinitions as $columnIndex => $attribute) { foreach ($columnDefinitions as $columnIndex => $attribute) {
$value = $worksheet->getCell(sprintf('%s%d', $columnIndex, $row->getRowIndex()))->getValueString(); $value = $worksheet->getCell(sprintf('%s%d', $columnIndex, $row->getRowIndex()))->getValueString();
$value = trim($value);
switch(KeyAttribute::from($attribute)) { switch(KeyAttribute::from($attribute)) {
case KeyAttribute::NONE: case KeyAttribute::NONE:
break; break;
@ -122,11 +126,19 @@ final class GameImporter
if (empty($values['key']) || empty($values['name']) || empty($values['store'])) { if (empty($values['key']) || empty($values['name']) || empty($values['store'])) {
continue; continue;
} }
$game = $this->entityManager->getRepository(Game::class)->findOneBy([ 'name' => $values['name'] ]); $game = array_key_exists($values['name'], $foundGames) ? $foundGames[$values['name']] : null;
if ($game === null) {
$game = $this->entityManager->getRepository(Game::class)->findOneBy([ 'name' => $values['name'] ]);
}
if ($game === null) { if ($game === null) {
$game = new Game($values['name']); $game = new Game($values['name']);
$this->entityManager->persist($game);
} }
$foundGames[$values['name']] = $game;
$key = new Key( $key = new Key(
$game, $game,
@ -137,7 +149,6 @@ final class GameImporter
$values['from'], $values['from'],
); );
$this->entityManager->persist($game);
$this->entityManager->persist($key); $this->entityManager->persist($key);
$addedAmount++; $addedAmount++;
} }