diff --git a/src/Website/Command/ImportEscapeRoomsFromOsmCommand.php b/src/Website/Command/ImportEscapeRoomsFromOsmCommand.php index cf92ede..aa3e568 100644 --- a/src/Website/Command/ImportEscapeRoomsFromOsmCommand.php +++ b/src/Website/Command/ImportEscapeRoomsFromOsmCommand.php @@ -235,7 +235,7 @@ final class ImportEscapeRoomsFromOsmCommand extends Command private function upsert(array $element, bool $dryRun): string { $tags = $element['tags'] ?? []; - $name = trim((string) ($tags['name'] ?? '')); + $name = mb_substr(trim((string) ($tags['name'] ?? '')), 0, 255); if ($name === '') { return 'noname'; } @@ -263,16 +263,18 @@ final class ImportEscapeRoomsFromOsmCommand extends Command ->setOsmId($osmId); } + // Clamp each value to its column width - OSM address tags are free text + // and occasionally blow past these (e.g. addr:housenumber "12-14, 16, 18"). $room ->setName($name) - ->setVenue($this->firstTag($tags, ['brand', 'operator'])) - ->setStreet($this->firstTag($tags, ['addr:street'])) - ->setHouseNumber($this->firstTag($tags, ['addr:housenumber'])) - ->setPostcode($this->firstTag($tags, ['addr:postcode'])) - ->setCity($this->firstTag($tags, ['addr:city', 'addr:town', 'addr:suburb'])) - ->setCountry($this->normaliseCountry($this->firstTag($tags, ['addr:country']))) - ->setWebsite($this->firstTag($tags, ['website', 'contact:website', 'url'])) - ->setPhone($this->firstTag($tags, ['phone', 'contact:phone'])) + ->setVenue($this->firstTag($tags, ['brand', 'operator'], 255)) + ->setStreet($this->firstTag($tags, ['addr:street'], 255)) + ->setHouseNumber($this->firstTag($tags, ['addr:housenumber'], 32)) + ->setPostcode($this->firstTag($tags, ['addr:postcode'], 32)) + ->setCity($this->firstTag($tags, ['addr:city', 'addr:town', 'addr:suburb'], 128)) + ->setCountry($this->normaliseCountry($this->firstTag($tags, ['addr:country'], 8))) + ->setWebsite($this->firstTag($tags, ['website', 'contact:website', 'url'], 511)) + ->setPhone($this->firstTag($tags, ['phone', 'contact:phone'], 64)) ->setLatitude($lat) ->setLongitude($lng); @@ -306,15 +308,17 @@ final class ImportEscapeRoomsFromOsmCommand extends Command } /** + * First non-empty value among $keys, trimmed and clamped to $maxLen chars. + * * @param array $tags * @param string[] $keys */ - private function firstTag(array $tags, array $keys): ?string + private function firstTag(array $tags, array $keys, int $maxLen = 255): ?string { foreach ($keys as $key) { $value = trim((string) ($tags[$key] ?? '')); if ($value !== '') { - return mb_substr($value, 0, 500); + return mb_substr($value, 0, $maxLen); } }