diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository_SnapshotStore.cs b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository_SnapshotStore.cs index ed89ce498..03222b9cf 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository_SnapshotStore.cs +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository_SnapshotStore.cs @@ -93,36 +93,32 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents private async Task UpsertDraftContentAsync(ContentDomainObject.State value, long oldVersion, long newVersion) { - var content = SimpleMapper.Map(value, new MongoContentEntity - { - IndexedAppId = value.AppId.Id, - IndexedSchemaId = value.SchemaId.Id, - Version = newVersion - }); - - content.DocumentId = value.UniqueId; - content.ScheduledAt = value.ScheduleJob?.DueTime; - content.ScheduleJob = value.ScheduleJob; - content.NewStatus = value.NewStatus; + var content = CreateContent(value, value.Data, newVersion); await collectionAll.UpsertVersionedAsync(content.DocumentId, oldVersion, content); } private async Task UpsertPublishedContentAsync(ContentDomainObject.State value, long oldVersion, long newVersion) { - var content = SimpleMapper.Map(value, new MongoContentEntity - { - IndexedAppId = value.AppId.Id, - IndexedSchemaId = value.SchemaId.Id, - Version = newVersion - }); + var content = CreateContent(value, value.CurrentVersion.Data, newVersion); + + await collectionPublished.UpsertVersionedAsync(content.DocumentId, oldVersion, content); + } + + private static MongoContentEntity CreateContent(ContentDomainObject.State value, ContentData data, long newVersion) + { + var content = SimpleMapper.Map(value, new MongoContentEntity()); + content.Data = data; content.DocumentId = value.UniqueId; + content.IndexedAppId = value.AppId.Id; + content.IndexedSchemaId = value.SchemaId.Id; + content.NewStatus = null; content.ScheduledAt = null; content.ScheduleJob = null; - content.NewStatus = null; + content.Version = newVersion; - await collectionPublished.UpsertVersionedAsync(content.DocumentId, oldVersion, content); + return content; } } } diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Squidex.Domain.Apps.Entities.MongoDb.csproj b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Squidex.Domain.Apps.Entities.MongoDb.csproj index 4d514ee6e..95e6b96c6 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Squidex.Domain.Apps.Entities.MongoDb.csproj +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Squidex.Domain.Apps.Entities.MongoDb.csproj @@ -17,7 +17,7 @@ - + diff --git a/backend/src/Squidex.Domain.Users.MongoDb/Squidex.Domain.Users.MongoDb.csproj b/backend/src/Squidex.Domain.Users.MongoDb/Squidex.Domain.Users.MongoDb.csproj index 6f3bfd153..a2ed44f76 100644 --- a/backend/src/Squidex.Domain.Users.MongoDb/Squidex.Domain.Users.MongoDb.csproj +++ b/backend/src/Squidex.Domain.Users.MongoDb/Squidex.Domain.Users.MongoDb.csproj @@ -20,7 +20,7 @@ - + diff --git a/backend/src/Squidex.Infrastructure.MongoDb/Squidex.Infrastructure.MongoDb.csproj b/backend/src/Squidex.Infrastructure.MongoDb/Squidex.Infrastructure.MongoDb.csproj index 32b180777..12b3bfcae 100644 --- a/backend/src/Squidex.Infrastructure.MongoDb/Squidex.Infrastructure.MongoDb.csproj +++ b/backend/src/Squidex.Infrastructure.MongoDb/Squidex.Infrastructure.MongoDb.csproj @@ -13,8 +13,8 @@ - - + + diff --git a/backend/src/Squidex/Squidex.csproj b/backend/src/Squidex/Squidex.csproj index 2ddcdc56c..0d4017d05 100644 --- a/backend/src/Squidex/Squidex.csproj +++ b/backend/src/Squidex/Squidex.csproj @@ -48,7 +48,7 @@ - + diff --git a/backend/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs b/backend/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs index c5e767613..2038c4bcf 100644 --- a/backend/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs +++ b/backend/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs @@ -415,6 +415,42 @@ namespace TestSuite.ApiTests } } + [Fact] + public async Task Should_create_draft_version() + { + TestEntity content = null; + try + { + // STEP 1: Create a new item. + content = await _.Contents.CreateAsync(new TestEntityData { Number = 1 }, true); + + + // STEP 2: Create draft. + content = await _.Contents.CreateDraftAsync(content.Id); + + + // STEP 3: Update the item and ensure that the data has not changed. + await _.Contents.PatchAsync(content.Id, new TestEntityData { Number = 2 }); + + var updated = await _.Contents.GetAsync(content.Id); + + Assert.Equal(1, updated.Data.Number); + + + // STEP 4: Get the unpublished version + var unpublished = await _.Contents.GetAsync(content.Id, QueryContext.Default.Unpublished()); + + Assert.Equal(2, unpublished.Data.Number); + } + finally + { + if (content != null) + { + await _.Contents.DeleteAsync(content.Id); + } + } + } + [Fact] public async Task Should_delete_item() {