Skip to content
Merged

Dev #3225

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions app/Imports/MatchmakingProfileImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ protected function parseDate($value): ?Carbon
*/
protected function extractCountryName($locationString): string
{
$locationString = str_replace("\xc2\xa0", ' ', $locationString);
$locationString = trim($locationString);
$locationString = trim($locationString, "\"' ");
$locationString = preg_replace('/\s+/', ' ', $locationString);

// Common country names to look for
$countryNames = [
Expand Down Expand Up @@ -118,6 +121,12 @@ protected function extractCountryName($locationString): string
}
}

// Try taking the last non-empty part (often the country is last)
$parts = array_filter(array_map('trim', preg_split('/[,\/;|]/', $locationString)));
if (!empty($parts)) {
return trim(end($parts));
}

// If still no match, return the original string (trimmed)
return trim($locationString);
}
Expand All @@ -133,6 +142,16 @@ protected function findCountryIso($countryName): ?string

$trimmedName = trim($countryName);
$lowerName = mb_strtolower($trimmedName);

// If already an ISO code
if (strlen($trimmedName) === 2) {
$iso = strtoupper($trimmedName);
$country = Country::where('iso', $iso)->first();
if ($country) {
Log::info("Country found (iso): {$trimmedName} -> {$country->iso}");
return $country->iso;
}
}

// Try exact match first
$country = Country::where('name', $trimmedName)->first();
Expand Down Expand Up @@ -235,6 +254,10 @@ protected function normalizeRowKeys(array $row): array
if (!array_key_exists($normalizedKey, $normalized)) {
$normalized[$normalizedKey] = $value;
}
$compactKey = str_replace('_', '', $normalizedKey);
if (!array_key_exists($compactKey, $normalized)) {
$normalized[$compactKey] = $value;
}
}
return $normalized;
}
Expand Down
Loading