Skip to content

Commit

Permalink
Fix buggy card row (LO-3558)
Browse files Browse the repository at this point in the history
  • Loading branch information
amcsi committed Apr 23, 2024
1 parent 543d108 commit 4c8f1f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
25 changes: 11 additions & 14 deletions app/Import/CsvIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,26 @@ public function getIterator()
$f = try_fopen(storage_path(ImportConstants::CSV_PATH), 'r');

$expectedColumnCount = 22;
$expectedCommaCount = $expectedColumnCount - 1;

$rows = [];

while (($row = fgets($f)) !== false) {
while (($commaCount = substr_count($row, ',')) < $expectedCommaCount) {
$additionalRow = fgets($f);
if (!$additionalRow) {
throw new \RuntimeException("Could not get any more rows.");
}
$row .= $additionalRow;
}
if ($commaCount > $expectedCommaCount) {
throw new \RuntimeException("Comma count went over $expectedCommaCount.");
}
$rows[] = $row;
}

$rows = array_reverse($rows);
// Explode by comma.
$reader = (function () use ($rows) {
foreach ($rows as $row) {
yield array_map(trim(...), explode(',', $row));
$reader = (function () use ($rows, $expectedColumnCount) {
foreach ($rows as $line) {
$row = array_map(trim(...), explode(',', $line));
if ($row[CsvColumns::ID] === 'LO-3558' && $row[CsvColumns::TYPE] === '向坂 海希') {
$row = array_merge(array_slice($row, 0, CsvColumns::TYPE), array_slice($row, CsvColumns::TYPE + 1));
}
$columnCount = count($row);
if ($columnCount > $expectedColumnCount) {
throw new \RuntimeException("Column count went over $expectedColumnCount.");
}
yield $row;
}
})();

Expand Down
4 changes: 0 additions & 4 deletions app/Import/CsvValueInterpreter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ public static function getType(array $csvRow): int
case 'エリア':
return Type::AREA;
default:
// TODO: remove if the original CSV gets fixed.
if ($csvRow[CsvColumns::ID] === 'LO-2156') {
return Type::CHARACTER;
}
throw new \InvalidArgumentException("Unknown Type: $cellValue");
}
}
Expand Down

0 comments on commit 4c8f1f0

Please sign in to comment.