legacy: fix-timestamps liest Legacy-Schema-Namen aus der DB-Config statt hartkodiert

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 <noreply@anthropic.com>
This commit is contained in:
Kevin Adametz 2026-07-20 10:50:39 +00:00
parent 3151b1f38a
commit 7971656025

View file

@ -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'];