From 56fee01322e651832e31e3ba042d20c549612835 Mon Sep 17 00:00:00 2001 From: Michel Date: Fri, 8 Nov 2024 14:49:04 +0100 Subject: [PATCH] Improves game importer --- src/php/Importer/GameImporter.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/php/Importer/GameImporter.php b/src/php/Importer/GameImporter.php index b686d12..dd275db 100644 --- a/src/php/Importer/GameImporter.php +++ b/src/php/Importer/GameImporter.php @@ -83,6 +83,9 @@ final class GameImporter $totalRows = 0; $addedAmount = 0; + + $foundGames = []; + $rowValues = []; foreach ($worksheet->getRowIterator(self::HEADER_ROW_INDEX + 1) as $row) { $totalRows++; @@ -96,7 +99,8 @@ final class GameImporter foreach ($columnDefinitions as $columnIndex => $attribute) { $value = $worksheet->getCell(sprintf('%s%d', $columnIndex, $row->getRowIndex()))->getValueString(); - + $value = trim($value); + switch(KeyAttribute::from($attribute)) { case KeyAttribute::NONE: break; @@ -122,11 +126,19 @@ final class GameImporter if (empty($values['key']) || empty($values['name']) || empty($values['store'])) { 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) { $game = new Game($values['name']); + $this->entityManager->persist($game); } + + $foundGames[$values['name']] = $game; $key = new Key( $game, @@ -137,7 +149,6 @@ final class GameImporter $values['from'], ); - $this->entityManager->persist($game); $this->entityManager->persist($key); $addedAmount++; }