diff --git a/app/Console/Commands/FixLegacyTimestamps.php b/app/Console/Commands/FixLegacyTimestamps.php index 97eb5be5..201ab5be 100644 --- a/app/Console/Commands/FixLegacyTimestamps.php +++ b/app/Console/Commands/FixLegacyTimestamps.php @@ -26,9 +26,10 @@ class FixLegacyTimestamps extends Command protected $description = 'Korrigiert created_at/updated_at auf importierten Datensätzen aus den Legacy-DBs.'; - private const PORTAL_DB = [ - 'presseecho' => 'presseecho', - 'businessportal24' => 'businessportal', + /** Mapping: Portal → Legacy-Connection; der Schema-Name kommt aus deren Config (.env). */ + private const PORTAL_CONNECTIONS = [ + 'presseecho' => 'mysql_presseecho', + 'businessportal24' => 'mysql_businessportal', ]; /** Mapping: neue Tabelle → (legacy_portal, legacy_db, legacy_table, legacy_created_col) */ @@ -69,7 +70,7 @@ class FixLegacyTimestamps extends Command $isDryRun = (bool) $this->option('dry-run'); $entities = $entityOpt === 'all' ? array_keys(self::ENTITY_CONFIG) : [$entityOpt]; - $portals = $portalOpt === 'all' ? array_keys(self::PORTAL_DB) : [$portalOpt]; + $portals = $portalOpt === 'all' ? array_keys(self::PORTAL_CONNECTIONS) : [$portalOpt]; if ($isDryRun) { $this->warn('[DRY-RUN] Kein tatsächlicher Schreibvorgang.'); @@ -87,9 +88,9 @@ class FixLegacyTimestamps extends Command } foreach ($portals as $portal) { - $legacyDb = self::PORTAL_DB[$portal] ?? null; + $legacyDb = $this->legacySchema($portal); if (! $legacyDb) { - $this->error("Unbekanntes Portal: {$portal}"); + $this->error("Unbekanntes Portal oder fehlende Legacy-DB-Config: {$portal}"); continue; } @@ -108,6 +109,19 @@ class FixLegacyTimestamps extends Command return self::SUCCESS; } + private function legacySchema(string $portal): ?string + { + $connection = self::PORTAL_CONNECTIONS[$portal] ?? null; + + if ($connection === null) { + return null; + } + + $database = config("database.connections.{$connection}.database"); + + return is_string($database) && $database !== '' ? $database : null; + } + private function fixEntity(array $config, string $portal, string $legacyDb, bool $isDryRun): int { $newTable = $config['new_table'];