From df4888c5772016c58834858a4f09f60ff54c3733 Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Wed, 3 Dec 2025 18:42:45 -0600 Subject: [PATCH] Bounce scripts in queue if game hasn't been imported --- .../Importers/ScriptImporter.cs | 61 +++++++++++++------ 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/LANCommander.Server.ImportExport/Importers/ScriptImporter.cs b/LANCommander.Server.ImportExport/Importers/ScriptImporter.cs index f9c1182d..488c02d2 100644 --- a/LANCommander.Server.ImportExport/Importers/ScriptImporter.cs +++ b/LANCommander.Server.ImportExport/Importers/ScriptImporter.cs @@ -59,11 +59,26 @@ public class ScriptImporter( }; if (ImportContext.Manifest is Game game) + { + if (ImportContext.InQueue(game, gameImporter)) + return false; + newScript.Game = await gameService.GetAsync(game.Id); + } else if (ImportContext.Manifest is Redistributable redistributable) + { + if (ImportContext.InQueue(redistributable, redistributableImporter)) + return false; + newScript.Redistributable = await redistributableService.GetAsync(redistributable.Id); + } else if (ImportContext.Manifest is SDK.Models.Manifest.Server server) + { + if (ImportContext.InQueue(server, serverImporter)) + return false; + newScript.Server = await serverService.GetAsync(server.Id); + } else return false; @@ -90,20 +105,37 @@ public class ScriptImporter( { var archiveEntry = ImportContext.Archive.Entries.FirstOrDefault(e => e.Key == $"Scripts/{record.Id}"); - Data.Models.Script existing = null; - - if (ImportContext.Manifest is Game game) - existing = await scriptService.FirstOrDefaultAsync(s => s.Type == record.Type && s.Name == record.Name && s.GameId == game.Id); - else if (ImportContext.Manifest is Redistributable redistributable) - existing = await scriptService.FirstOrDefaultAsync(s => s.Type == record.Type && s.Name == record.Name && s.RedistributableId == redistributable.Id); - else if (ImportContext.Manifest is SDK.Models.Manifest.Server server) - existing = await scriptService.FirstOrDefaultAsync(s => s.Type == record.Type && s.Name == record.Name && s.ServerId == server.Id); + Data.Models.Script existing = await scriptService.FirstOrDefaultAsync(s => s.Id == record.Id); if (existing == null) return false; try { + if (ImportContext.Manifest is Game game) + { + if (ImportContext.InQueue(game, gameImporter)) + return false; + + existing.Game = await gameService.GetAsync(game.Id); + } + else if (ImportContext.Manifest is Redistributable redistributable) + { + if (ImportContext.InQueue(redistributable, redistributableImporter)) + return false; + + existing.Redistributable = await redistributableService.GetAsync(redistributable.Id); + } + else if (ImportContext.Manifest is SDK.Models.Manifest.Server server) + { + if (ImportContext.InQueue(server, serverImporter)) + return false; + + existing.Server = await serverService.GetAsync(server.Id); + } + else + return false; + existing.CreatedOn = record.CreatedOn; existing.Name = record.Name; existing.Description = record.Description; @@ -127,16 +159,5 @@ public class ScriptImporter( } public override async Task ExistsAsync(Script record) - { - if (ImportContext.Manifest is Game game) - return await scriptService.ExistsAsync(s => s.Type == record.Type && s.Name == record.Name && s.GameId == game.Id); - - if (ImportContext.Manifest is Redistributable redistributable) - return await scriptService.ExistsAsync(s => s.Type == record.Type && s.Name == record.Name && s.RedistributableId == redistributable.Id); - - if (ImportContext.Manifest is SDK.Models.Manifest.Server server) - return await scriptService.ExistsAsync(s => s.Type == record.Type && s.Name == record.Name && s.ServerId == server.Id); - - return false; - } + => await scriptService.ExistsAsync(record.Id); } \ No newline at end of file