Improves game importer
This commit is contained in:
parent
2d397e4dc4
commit
56fee01322
1 changed files with 15 additions and 4 deletions
|
@ -84,6 +84,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++;
|
||||||
$values = [
|
$values = [
|
||||||
|
@ -96,6 +99,7 @@ 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:
|
||||||
|
@ -123,11 +127,19 @@ final class GameImporter
|
||||||
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,
|
||||||
$list,
|
$list,
|
||||||
|
@ -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++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue