From 033e74addaef9683e2ea624f54ea07549d38dcff Mon Sep 17 00:00:00 2001 From: florianfederspiel Date: Wed, 3 Jun 2026 15:06:33 +0200 Subject: [PATCH] =?UTF-8?q?KI-AGENT:=20Matrix-Raumdaten=20nach=20Tenant-Im?= =?UTF-8?q?port=20zur=C3=BCcksetzen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/utils/tenantFullExport.ts | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/backend/src/utils/tenantFullExport.ts b/backend/src/utils/tenantFullExport.ts index 810023d..f032169 100644 --- a/backend/src/utils/tenantFullExport.ts +++ b/backend/src/utils/tenantFullExport.ts @@ -414,6 +414,45 @@ const prepareCommunicationRoomsForImport = (exportData: TenantFullExport) => { } } +const cleanupImportedCommunicationRooms = async (client: any, exportData: TenantFullExport) => { + const rows = exportData.tables.communication_rooms || [] + if (!rows.length) return 0 + + const tenantById = new Map((exportData.tables.tenants || []).map((tenant) => [ + Number(tenant.id), + { + id: Number(tenant.id), + name: tenant.name, + short: tenant.short, + }, + ])) + let cleaned = 0 + + for (const row of rows) { + const tenantId = Number(row.tenant_id) + const key = String(row.key || "") + const tenant = tenantById.get(tenantId) + if (!tenantId || !key || !tenant) continue + + const alias = tenantRoomAlias(tenant, key) + const result = await client.query( + ` + update communication_rooms + set matrix_room_id = null, + parent_space_room_id = null, + matrix_alias = $3, + updated_at = now() + where tenant_id = $1 and key = $2 + `, + [tenantId, key, alias] + ) + + cleaned += result.rowCount || 0 + } + + return cleaned +} + const prepareColumnValue = (value: any, isJsonColumn: boolean) => { if (!isJsonColumn || value === null || typeof value === "undefined") return value if (typeof value === "string") return value @@ -585,6 +624,11 @@ export const importTenantFullExport = async ( importedTables.push({ table, rows: count }) } + const cleanedCommunicationRooms = await cleanupImportedCommunicationRooms(client, exportData) + if (cleanedCommunicationRooms) { + importedTables.push({ table: "communication_rooms_matrix_reset", rows: cleanedCommunicationRooms }) + } + await refreshSequences(client, columnsByTable) await client.query("commit")