Clamp OSM import field values to their column widths
addr:housenumber / addr:postcode etc. are free-text in OSM and occasionally exceed the entity's VARCHAR limits (e.g. housenumber "12-14, 16, 18"), which aborted the whole --tiled run with a 1406 "Data too long" error. firstTag() now takes a max length and each field is clamped to its real column size. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -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<string, mixed> $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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user