info('Suche nach blockierten E-Mail-Adressen...'); $dryRun = $this->option('dry-run'); // Liste der blockierten Domains $blockedDomains = [ '@guest.booking.com', '@messages.homeaway.com', '@fewo.check24.de', '@booking.com', '@homeaway.com', '@check24.de', '@partner.booking.com', ]; $stats = [ 'found' => 0, 'deleted' => 0, ]; // Hole alle Newsletter-Kontakte $contacts = NewsletterContact::all(); $this->info("Prüfe {$contacts->count()} Kontakte..."); $bar = $this->output->createProgressBar($contacts->count()); $bar->start(); foreach ($contacts as $contact) { $emailLower = strtolower($contact->email); $isBlockedEmail = false; foreach ($blockedDomains as $domain) { if (str_ends_with($emailLower, strtolower($domain))) { $isBlockedEmail = true; break; } } if ($isBlockedEmail) { $stats['found']++; if ($dryRun) { $this->newLine(); $this->warn("Würde löschen: {$contact->email} (ID: {$contact->id})"); } else { // Log erstellen vor dem Löschen $contact->logs()->create([ 'action' => 'deleted', 'description' => 'Kontakt entfernt - blockierte E-Mail-Domain (Buchungsplattform-Alias)', ]); $contact->delete(); $stats['deleted']++; } } $bar->advance(); } $bar->finish(); $this->newLine(2); // Statistiken ausgeben if ($dryRun) { $this->info('Dry-Run abgeschlossen!'); $this->table( ['Statistik', 'Anzahl'], [ ['Gefundene blockierte E-Mails', $stats['found']], ] ); if ($stats['found'] > 0) { $this->newLine(); $this->info('Führe den Befehl ohne --dry-run aus, um die Kontakte zu löschen:'); $this->comment('php artisan newsletter:cleanup-blocked-emails'); } } else { $this->info('Bereinigung abgeschlossen!'); $this->table( ['Statistik', 'Anzahl'], [ ['Gefundene blockierte E-Mails', $stats['found']], ['Gelöschte Kontakte', $stats['deleted']], ] ); } return 0; } }