diff --git a/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs b/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs index 50d725d35..69d51774d 100644 --- a/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs +++ b/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs @@ -152,5 +152,10 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents callback(c); }); } + + public Task DeleteArchiveAsync() + { + return Database.DropCollectionAsync("States_Contents_Archive"); + } } } diff --git a/src/Squidex.Domain.Apps.Entities/Contents/ContentVersionLoader.cs b/src/Squidex.Domain.Apps.Entities/Contents/ContentVersionLoader.cs index 75b4bb248..d7c0dd7f1 100644 --- a/src/Squidex.Domain.Apps.Entities/Contents/ContentVersionLoader.cs +++ b/src/Squidex.Domain.Apps.Entities/Contents/ContentVersionLoader.cs @@ -38,6 +38,7 @@ namespace Squidex.Domain.Apps.Entities.Contents if (content.Version < version) { content = content.Apply(e); + content.Version++; } }); diff --git a/src/Squidex.Domain.Apps.Entities/DomainObjectState.cs b/src/Squidex.Domain.Apps.Entities/DomainObjectState.cs index 210617ff6..13ce32acc 100644 --- a/src/Squidex.Domain.Apps.Entities/DomainObjectState.cs +++ b/src/Squidex.Domain.Apps.Entities/DomainObjectState.cs @@ -40,7 +40,7 @@ namespace Squidex.Domain.Apps.Entities public Instant LastModified { get; set; } [JsonProperty] - public long Version { get; set; } + public long Version { get; set; } = EtagVersion.Empty; public T Clone() { diff --git a/src/Squidex/Config/Domain/EntitiesServices.cs b/src/Squidex/Config/Domain/EntitiesServices.cs index 5ce312227..6c6b98f40 100644 --- a/src/Squidex/Config/Domain/EntitiesServices.cs +++ b/src/Squidex/Config/Domain/EntitiesServices.cs @@ -161,13 +161,16 @@ namespace Squidex.Config.Domain services.AddTransientAs() .As(); + services.AddTransientAs() + .As(); + services.AddTransientAs() .As(); services.AddTransientAs() .As(); - services.AddTransientAs() + services.AddTransientAs() .As(); services.AddTransientAs() diff --git a/tests/RunCoverage.ps1 b/tests/RunCoverage.ps1 index 3b46fc1dc..27b2b5e1a 100644 --- a/tests/RunCoverage.ps1 +++ b/tests/RunCoverage.ps1 @@ -76,6 +76,6 @@ if ($all -Or $web) { -oldStyle } -&"$folderHome\.nuget\packages\ReportGenerator\3.1.1\tools\ReportGenerator.exe" ` +&"$folderHome\.nuget\packages\ReportGenerator\3.1.2\tools\ReportGenerator.exe" ` -reports:"$folderWorking\$folderReports\*.xml" ` -targetdir:"$folderWorking\$folderReports\Output" \ No newline at end of file diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Contents/ContentQueryServiceTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Contents/ContentQueryServiceTests.cs index 4cca28da4..654821aa3 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Contents/ContentQueryServiceTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Contents/ContentQueryServiceTests.cs @@ -147,25 +147,37 @@ namespace Squidex.Domain.Apps.Entities.Contents } [Fact] - public async Task Should_return_contents_with_ids_from_repository_and_transform() + public async Task Should_return_contents_with_ids_from_repository() { await TestManyIdRequest(true, false, new HashSet { Guid.NewGuid() }, Status.Draft, Status.Published); } [Fact] - public async Task Should_return_non_archived_contents_from_repository_and_transform() + public async Task Should_return_contents_with_ids_from_repository_and_transform_as_non_frontend() + { + await TestManyIdRequest(false, false, new HashSet { Guid.NewGuid() }, Status.Published); + } + + [Fact] + public async Task Should_return_non_archived_contents_from_repository() { await TestManyRequest(true, false, Status.Draft, Status.Published); } [Fact] - public async Task Should_return_archived_contents_from_repository_and_transform() + public async Task Should_return_non_archived_contents_from_repository_and_transform_as_non_frontend() + { + await TestManyRequest(false, false, Status.Published); + } + + [Fact] + public async Task Should_return_archived_contents_from_repository() { await TestManyRequest(true, true, Status.Archived); } [Fact] - public async Task Should_return_draft_contents_from_repository_and_transform() + public async Task Should_return_draft_contents_from_repository() { await TestManyRequest(false, false, Status.Published); } @@ -189,6 +201,17 @@ namespace Squidex.Domain.Apps.Entities.Contents Assert.Equal(content.Id, result[0].Id); Assert.Equal(123, result.Total); + + if (!isFrontend) + { + A.CallTo(() => scriptEngine.Transform(A.Ignored, A.Ignored)) + .MustHaveHappened(Repeated.Exactly.Times(result.Count)); + } + else + { + A.CallTo(() => scriptEngine.Transform(A.Ignored, A.Ignored)) + .MustNotHaveHappened(); + } } private async Task TestManyIdRequest(bool isFrontend, bool archive, HashSet ids, params Status[] status) @@ -204,6 +227,17 @@ namespace Squidex.Domain.Apps.Entities.Contents Assert.Equal(content.Id, result[0].Id); Assert.Equal(123, result.Total); + + if (!isFrontend) + { + A.CallTo(() => scriptEngine.Transform(A.Ignored, A.Ignored)) + .MustHaveHappened(Repeated.Exactly.Times(result.Count)); + } + else + { + A.CallTo(() => scriptEngine.Transform(A.Ignored, A.Ignored)) + .MustNotHaveHappened(); + } } private void SetupClaims(bool isFrontend) diff --git a/tools/Migrate_01/Migrate_01.csproj b/tools/Migrate_01/Migrate_01.csproj index 9db8eb6c0..27d9fd97a 100644 --- a/tools/Migrate_01/Migrate_01.csproj +++ b/tools/Migrate_01/Migrate_01.csproj @@ -4,6 +4,7 @@ + diff --git a/tools/Migrate_01/MigrationPath.cs b/tools/Migrate_01/MigrationPath.cs index ff7efb52d..81eb97d0d 100644 --- a/tools/Migrate_01/MigrationPath.cs +++ b/tools/Migrate_01/MigrationPath.cs @@ -15,7 +15,7 @@ namespace Migrate_01 { public sealed class MigrationPath : IMigrationPath { - private const int CurrentVersion = 7; + private const int CurrentVersion = 8; private readonly IServiceProvider serviceProvider; public MigrationPath(IServiceProvider serviceProvider) @@ -56,6 +56,8 @@ namespace Migrate_01 migrations.Add(serviceProvider.GetRequiredService()); } + migrations.Add(serviceProvider.GetRequiredService()); + return (CurrentVersion, migrations); } } diff --git a/tools/Migrate_01/Migrations/DeleteArchiveCollection.cs b/tools/Migrate_01/Migrations/DeleteArchiveCollection.cs new file mode 100644 index 000000000..0ae22145e --- /dev/null +++ b/tools/Migrate_01/Migrations/DeleteArchiveCollection.cs @@ -0,0 +1,32 @@ +// ========================================================================== +// Squidex Headless CMS +// ========================================================================== +// Copyright (c) Squidex UG (haftungsbeschraenkt) +// All rights reserved. Licensed under the MIT license. +// ========================================================================== + +using System.Threading.Tasks; +using Squidex.Domain.Apps.Entities.Contents.Repositories; +using Squidex.Domain.Apps.Entities.MongoDb.Contents; +using Squidex.Infrastructure.Migrations; + +namespace Migrate_01.Migrations +{ + public sealed class DeleteArchiveCollection : IMigration + { + private readonly IContentRepository contentRepository; + + public DeleteArchiveCollection(IContentRepository contentRepository) + { + this.contentRepository = contentRepository; + } + + public async Task UpdateAsync() + { + if (contentRepository is MongoContentRepository mongoContentRepository) + { + await mongoContentRepository.DeleteArchiveAsync(); + } + } + } +} diff --git a/tools/Migrate_01/Migrations/RebuildAssets.cs b/tools/Migrate_01/Migrations/RebuildAssets.cs index 2714c1269..db9ad1bd6 100644 --- a/tools/Migrate_01/Migrations/RebuildAssets.cs +++ b/tools/Migrate_01/Migrations/RebuildAssets.cs @@ -10,7 +10,7 @@ using Squidex.Infrastructure.Migrations; namespace Migrate_01 { - public class RebuildAssets : IMigration + public sealed class RebuildAssets : IMigration { private readonly Rebuilder rebuilder; diff --git a/tools/Migrate_01/Migrations/RebuildContents.cs b/tools/Migrate_01/Migrations/RebuildContents.cs index d7d11a7a7..53cd96961 100644 --- a/tools/Migrate_01/Migrations/RebuildContents.cs +++ b/tools/Migrate_01/Migrations/RebuildContents.cs @@ -10,7 +10,7 @@ using Squidex.Infrastructure.Migrations; namespace Migrate_01.Migrations { - public class RebuildContents : IMigration + public sealed class RebuildContents : IMigration { private readonly Rebuilder rebuilder;