From 2765afec2ffb186b19017c58b7a59bee63770cc2 Mon Sep 17 00:00:00 2001 From: Kevin Adametz Date: Mon, 20 Jul 2026 10:50:39 +0000 Subject: [PATCH] legacy: fix-timestamps liest Legacy-Schema-Namen aus der DB-Config statt hartkodiert MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Die Cross-Schema-JOINs zeigten fest auf `presseecho`/`businessportal` — auf dem Live-Server heißen die Schemas aber anders (lokale Snapshot-Kopien der KAS-Datenbanken). Der Schema-Name kommt jetzt aus der database-Config der jeweiligen Legacy-Connection (DB_DATABASE_PRESSEECHO/_BUSINESSPORTAL), derselben Quelle, die auch legacy:import nutzt. Co-Authored-By: Claude Fable 5 --- app/Console/Commands/FixLegacyTimestamps.php | 26 +++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) 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'];