Skip to content
Merged

Dev #3235

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
37 changes: 28 additions & 9 deletions app/Imports/MatchmakingProfileImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,21 +232,25 @@ protected function findCountryIso($countryName): ?string
}

/**
* Generate slug from organisation name or email
* Generate slug from a base string
*/
protected function generateSlug($organisationName, $email): string
protected function generateSlug(string $base): string
{
$base = !empty($organisationName) ? $organisationName : $email;
$base = trim($base);
$slug = Str::slug($base);


if ($slug === '') {
$slug = 'profile';
}

// Ensure uniqueness
$originalSlug = $slug;
$counter = 1;
while (MatchmakingProfile::where('slug', $slug)->exists()) {
$slug = $originalSlug . '-' . $counter;
$counter++;
}

return $slug;
}

Expand Down Expand Up @@ -509,17 +513,32 @@ public function model(array $row): ?Model
$lastName = count($parts) ? implode(' ', $parts) : null;
}

// Build slug base
$slugBase = null;
if ($type === MatchmakingProfile::TYPE_VOLUNTEER) {
$nameParts = array_filter([trim((string) $firstName), trim((string) $lastName)]);
if (!empty($nameParts)) {
$slugBase = implode(' ', $nameParts);
} elseif (!empty($fullName)) {
$slugBase = $fullName;
} elseif (!empty($email)) {
$slugBase = $email;
} else {
$slugBase = $organisationName ?: 'profile';
}
} else {
$slugBase = $organisationName ?: ($email ?: 'profile');
}

Log::info('[MatchmakingProfileImport] Processing row', [
'type' => $type,
'email' => $email,
'organisation_name' => $organisationName,
'slug_base' => $slugBase,
]);

// Generate slug
$slug = $this->generateSlug(
$organisationName ?? '',
$email ?? 'anonymous'
);
$slug = $this->generateSlug($slugBase);

// Parse organisation type
$organisationType = [];
Expand Down
Loading