service = $service; } public function handle() { $this->info('Starting avatar migration...'); // Try to read legacy data from user_profiles.avatar_legacy or users.avatar_legacy or users.icon $rows = DB::table('user_profiles')->select('user_id', 'avatar_legacy')->whereNotNull('avatar_legacy')->get(); if ($rows->isEmpty()) { // fallback to users table $rows = DB::table('users')->select('user_id', 'icon as avatar_legacy')->whereNotNull('icon')->get(); } $count = 0; foreach ($rows as $row) { $userId = $row->user_id; $legacy = $row->avatar_legacy ?? null; if (!$legacy) { continue; } // Try common legacy paths $candidates = [ public_path('user-picture/' . $legacy), public_path('avatar/' . $userId . '/' . $legacy), storage_path('app/public/user-picture/' . $legacy), storage_path('app/public/avatar/' . $userId . '/' . $legacy), ]; $found = false; foreach ($candidates as $p) { if (file_exists($p) && is_readable($p)) { $this->info("Processing user {$userId} from {$p}"); $hash = $this->service->storeFromLegacyFile($userId, $p); if ($hash) { $this->info(" -> migrated, hash={$hash}"); $count++; $found = true; break; } } } if (!$found) { $this->warn("Legacy file not found for user {$userId}, filename={$legacy}"); } } $this->info("Migration complete. Processed: {$count}"); return 0; } }