Skip to content
Merged
Show file tree
Hide file tree
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
130 changes: 130 additions & 0 deletions app/Console/Commands/MatchmakingApplyDeaUpdateJuly2026.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

namespace App\Console\Commands;

use App\Imports\MatchmakingProfileImport;
use App\MatchmakingProfile;
use App\Services\Matchmaking\ProfileAvatarResolver;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use Maatwebsite\Excel\Facades\Excel;

class MatchmakingApplyDeaUpdateJuly2026 extends Command
{
protected $signature = 'matchmaking:apply-dea-update-2026-07
{--dry-run : Preview without writing}
{--skip-import : Only remove old CityLab / sync avatars}';

protected $description = 'Apply Dea matchmaking update: add Sophia Drakaki, replace CityLab org with the completed registration, sync avatars';

public function handle(ProfileAvatarResolver $resolver): int
{
$dryRun = (bool) $this->option('dry-run');

$cityLabs = MatchmakingProfile::query()
->where(function ($q) {
$q->whereRaw('LOWER(TRIM(COALESCE(organisation_name, \'\'))) = ?', ['citylab'])
->orWhereRaw('LOWER(TRIM(COALESCE(organisation_name, \'\'))) like ?', ['citylab%'])
->orWhereRaw('LOWER(TRIM(COALESCE(organisation_name, \'\'))) like ?', ['% citylab%'])
->orWhereRaw('LOWER(TRIM(COALESCE(email, \'\'))) like ?', ['%@citylab.gr']);
})
->where('type', MatchmakingProfile::TYPE_ORGANISATION)
->get();

$this->info('Existing CityLab organisation profiles: '.$cityLabs->count());
foreach ($cityLabs as $profile) {
$this->line(sprintf(
' #%d %s <%s> slug=%s',
$profile->id,
$profile->organisation_name,
$profile->email,
$profile->slug
));
}

if (! $dryRun) {
foreach ($cityLabs as $profile) {
$profile->delete();
$this->warn("Removed CityLab organisation #{$profile->id}");
}
} else {
$this->line('[DRY] Would remove '.$cityLabs->count().' CityLab organisation profile(s)');
}

if (! $this->option('skip-import')) {
$indiv = base_path('database/seeders/data/matchmaking/sophia-drakaki-individual.xlsx');
$org = base_path('database/seeders/data/matchmaking/citylab-organisation-updated.xlsx');

foreach ([$indiv, $org] as $path) {
if (! is_file($path)) {
$this->error("Missing import file: {$path}");

return self::FAILURE;
}
}

if ($dryRun) {
$this->line('[DRY] Would import: '.$org);
$this->line('[DRY] Would import: '.$indiv);
} else {
// Organisation first, then individual (same org name must not collide).
Log::info('[MatchmakingApplyDeaUpdateJuly2026] Importing updated CityLab');
Excel::import(new MatchmakingProfileImport, $org);
$this->info('Imported updated CityLab organisation registration');

Log::info('[MatchmakingApplyDeaUpdateJuly2026] Importing Sophia Drakaki');
Excel::import(new MatchmakingProfileImport, $indiv);
$this->info('Imported Sophia Drakaki individual registration');
}
}

$targets = MatchmakingProfile::query()
->where(function ($q) {
$q->where(function ($inner) {
$inner->where('type', MatchmakingProfile::TYPE_VOLUNTEER)
->whereRaw('LOWER(TRIM(last_name)) = ?', ['drakaki']);
})->orWhere(function ($inner) {
$inner->where('type', MatchmakingProfile::TYPE_ORGANISATION)
->whereRaw('LOWER(TRIM(COALESCE(organisation_name, \'\'))) = ?', ['citylab']);
});
})
->get();

if ($targets->isEmpty() && ! $dryRun) {
$this->warn('No Sophia/CityLab profiles found after import to sync avatars.');
}

foreach ($targets as $profile) {
$resolved = $resolver->resolveForProfile($profile);
$label = $profile->type === MatchmakingProfile::TYPE_VOLUNTEER
? trim(($profile->first_name ?? '').' '.($profile->last_name ?? ''))
: (string) ($profile->organisation_name ?: ('Profile #'.$profile->id));
if ($label === '') {
$label = 'Profile #'.$profile->id;
}

if (empty($resolved)) {
$this->warn("No avatar match for {$label}");
continue;
}

if ($profile->avatar === $resolved) {
$this->line("Avatar already set for {$label}: {$resolved}");
continue;
}

if ($dryRun) {
$this->line("[DRY] Would set avatar for {$label} -> {$resolved}");
} else {
$profile->avatar = $resolved;
$profile->save();
$this->info("Set avatar for {$label} -> {$resolved}");
}
}

$this->newLine();
$this->info('Done. On production, run: php artisan matchmaking:apply-dea-update-2026-07');

return self::SUCCESS;
}
}
25 changes: 2 additions & 23 deletions app/Imports/MatchmakingProfileImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -750,18 +750,12 @@ public function model(array $row): ?Model
$trimmedOrgName = trim($organisationName);
$lowerOrgName = mb_strtolower($trimmedOrgName);

// First try with type constraint
// Match organisations only against organisation profiles.
// Volunteers often share organisation_name (e.g. CityLab) and must not be overwritten.
$existingProfile = MatchmakingProfile::where('type', MatchmakingProfile::TYPE_ORGANISATION)
->whereRaw('LOWER(TRIM(COALESCE(organisation_name, \'\'))) = ?', [$lowerOrgName])
->first();

// If not found, try without type constraint (in case type was set incorrectly)
if (!$existingProfile) {
$existingProfile = MatchmakingProfile::whereRaw('LOWER(TRIM(COALESCE(organisation_name, \'\'))) = ?', [$lowerOrgName])
->whereNotNull('organisation_name')
->first();
}

// Log for debugging
if ($existingProfile) {
Log::info('[MatchmakingProfileImport] Found existing organisation', [
Expand All @@ -784,18 +778,10 @@ public function model(array $row): ?Model
$trimmedEmail = trim($email);
$lowerEmail = mb_strtolower($trimmedEmail);

// First try with type constraint
$existingProfile = MatchmakingProfile::where('type', MatchmakingProfile::TYPE_VOLUNTEER)
->whereRaw('LOWER(TRIM(email)) = ?', [$lowerEmail])
->first();

// If not found, try without type constraint (in case type was set incorrectly)
if (!$existingProfile) {
$existingProfile = MatchmakingProfile::whereRaw('LOWER(TRIM(email)) = ?', [$lowerEmail])
->whereNotNull('email')
->first();
}

// Log for debugging
if ($existingProfile) {
Log::info('[MatchmakingProfileImport] Found existing volunteer by email', [
Expand Down Expand Up @@ -823,13 +809,6 @@ public function model(array $row): ?Model
->whereRaw('LOWER(TRIM(last_name)) = ?', [$last])
->first();

// If not found, try without type constraint (in case type was set incorrectly)
if (!$existingProfile) {
$existingProfile = MatchmakingProfile::whereRaw('LOWER(TRIM(first_name)) = ?', [$first])
->whereRaw('LOWER(TRIM(last_name)) = ?', [$last])
->first();
}

if ($existingProfile) {
Log::info('[MatchmakingProfileImport] Found existing volunteer by name', [
'id' => $existingProfile->id,
Expand Down
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading