23-01-2026
This commit is contained in:
parent
8fd1f4d451
commit
389d5d1820
59 changed files with 9642 additions and 883 deletions
122
app/Console/Commands/CleanupNewsletterBlockedEmails.php
Normal file
122
app/Console/Commands/CleanupNewsletterBlockedEmails.php
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\NewsletterContact;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class CleanupNewsletterBlockedEmails extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'newsletter:cleanup-blocked-emails {--dry-run : Nur anzeigen, ohne zu löschen}';
|
||||
|
||||
/**
|
||||
* The console description of the command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Entfernt Newsletter-Kontakte mit blockierten E-Mail-Adressen (Alias/Proxy von Buchungsplattformen)';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue