option('dry-run'); $this->info('DHL E-Mail Backfill gestartet'); $this->info('Modus: ' . ($dryRun ? 'DRY-RUN (keine Änderungen)' : 'LIVE')); $this->newLine(); // Hole alle Sendungen ohne E-Mail $shipments = DhlShipment::with('shoppingOrder.shopping_user') ->whereNull('email') ->orWhere('email', '') ->get(); $total = $shipments->count(); $updated = 0; $skipped = 0; $this->info("Gefundene Sendungen ohne E-Mail: {$total}"); $this->newLine(); $bar = $this->output->createProgressBar($total); foreach ($shipments as $shipment) { $bar->advance(); // Hole E-Mail aus Shopping User $email = null; if ($shipment->shoppingOrder && $shipment->shoppingOrder->shopping_user) { $email = $shipment->shoppingOrder->shopping_user->email; } if (empty($email)) { $skipped++; continue; } if (! $dryRun) { $shipment->email = $email; $shipment->save(); } $updated++; } $bar->finish(); $this->newLine(2); // Statistik $this->info('Backfill abgeschlossen!'); $this->newLine(); $this->table( ['Metrik', 'Anzahl'], [ ['Gesamt geprüft', $total], ['E-Mail gesetzt', $updated], ['Übersprungen (keine E-Mail)', $skipped], ] ); if ($dryRun) { $this->warn('DRY-RUN: Keine Änderungen wurden vorgenommen.'); $this->info('Führen Sie den Befehl ohne --dry-run aus, um die Änderungen zu speichern.'); } else { $this->info("{$updated} Sendungen wurden aktualisiert."); } return Command::SUCCESS; } }