From a3e6ef8e11f82a7a000cdb83be8857778e3ee35c Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 28 Jul 2021 15:26:48 +0200 Subject: [PATCH] Fix synchronization of singleton schemas. --- .../Squidex.CLI/Commands/App_Config.cs | 8 ++++++-- .../Sync/Contents/ContentsSynchronizer.cs | 4 +++- .../Implementation/Sync/Contents/Extensions.cs | 15 +++++++++++++-- cli/Squidex.CLI/Squidex.CLI/Squidex.CLI.csproj | 2 +- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Config.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Config.cs index 9db84a56..4d976383 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Config.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Config.cs @@ -63,9 +63,13 @@ public void Add(AddArguments arguments) if (arguments.Use) { configuration.UseApp(arguments.Name); - } - log.WriteLine("> App added."); + log.WriteLine("> App added and selected."); + } + else + { + log.WriteLine("> App added."); + } } [Command(Name = "use", Description = "Use an app.")] diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/Contents/ContentsSynchronizer.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/Contents/ContentsSynchronizer.cs index 9671402d..fd77f63e 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/Contents/ContentsSynchronizer.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/Contents/ContentsSynchronizer.cs @@ -89,6 +89,8 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s GetFiles(sync.FileSystem) .Select(x => (x, sync.Read(x, log))); + var schemas = await session.Schemas.GetSchemasAsync(session.App); + foreach (var (file, model) in models) { if (model?.Contents?.Count > 0) @@ -103,7 +105,7 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s DoNotScript = true, DoNotValidate = false, DoNotValidateWorkflow = true, - Jobs = model.Contents.Select(x => x.ToJob()).ToList() + Jobs = model.Contents.Select(x => x.ToJob(schemas)).ToList() }; var contentIdAssigned = false; diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/Contents/Extensions.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/Contents/Extensions.cs index ddbb097e..1c4395ab 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/Contents/Extensions.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/Contents/Extensions.cs @@ -9,16 +9,27 @@ using System.Linq; using Newtonsoft.Json.Linq; using Squidex.ClientLibrary; +using Squidex.ClientLibrary.Management; namespace Squidex.CLI.Commands.Implementation.Sync.Contents { public static class Extensions { - public static BulkUpdateJob ToJob(this ContentModel model) + public static BulkUpdateJob ToJob(this ContentModel model, SchemasDto schemas) { + var id = model.Id; + +#pragma warning disable CS0618 // Type or member is obsolete + var singleton = schemas.Items.Single(x => x.Name == model.Schema && x.IsSingleton); +#pragma warning restore CS0618 // Type or member is obsolete + if (singleton != null) + { + id = singleton.Id; + } + return new BulkUpdateJob { - Id = model.Id, + Id = id, Data = model.Data, Schema = model.Schema, Status = model.Status, diff --git a/cli/Squidex.CLI/Squidex.CLI/Squidex.CLI.csproj b/cli/Squidex.CLI/Squidex.CLI/Squidex.CLI.csproj index b6d58d17..9718a433 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Squidex.CLI.csproj +++ b/cli/Squidex.CLI/Squidex.CLI/Squidex.CLI.csproj @@ -14,7 +14,7 @@ net5.0 true sq - 7.9 + 7.10