diff --git a/src/Umbraco.Core/Models/ContentType.cs b/src/Umbraco.Core/Models/ContentType.cs index f4ff7bccf785..a2357e21ef49 100644 --- a/src/Umbraco.Core/Models/ContentType.cs +++ b/src/Umbraco.Core/Models/ContentType.cs @@ -13,7 +13,7 @@ namespace Umbraco.Cms.Core.Models /// [Serializable] [DataContract(IsReference = true)] - public class ContentType : ContentTypeCompositionBase, IContentType + public class ContentType : ContentTypeCompositionBase, IContentTypeWithHistoryCleanup { public const bool SupportsPublishingConst = true; diff --git a/src/Umbraco.Core/Models/ContentVersionCleanupPolicySettings.cs b/src/Umbraco.Core/Models/ContentVersionCleanupPolicySettings.cs index 5e3f319e6a73..b23e6c95fae5 100644 --- a/src/Umbraco.Core/Models/ContentVersionCleanupPolicySettings.cs +++ b/src/Umbraco.Core/Models/ContentVersionCleanupPolicySettings.cs @@ -1,6 +1,6 @@ using System; -namespace Umbraco.Core.Models +namespace Umbraco.Cms.Core.Models { public class ContentVersionCleanupPolicySettings { diff --git a/src/Umbraco.Core/Models/IContentType.cs b/src/Umbraco.Core/Models/IContentType.cs index cf4a347112d1..4025239a3fde 100644 --- a/src/Umbraco.Core/Models/IContentType.cs +++ b/src/Umbraco.Core/Models/IContentType.cs @@ -1,8 +1,19 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Umbraco.Cms.Core.Models.ContentEditing; namespace Umbraco.Cms.Core.Models { + [Obsolete("This will be merged into IContentType in Umbraco 10")] + public interface IContentTypeWithHistoryCleanup : IContentType + { + /// + /// Gets or Sets the history cleanup configuration + /// + HistoryCleanup HistoryCleanup { get; set; } + } + + /// /// Defines a ContentType, which Content is based on /// @@ -23,11 +34,6 @@ public interface IContentType : IContentTypeComposition /// IEnumerable AllowedTemplates { get; set; } - /// - /// Gets or Sets the history cleanup configuration - /// - HistoryCleanup HistoryCleanup { get; set; } - /// /// Determines if AllowedTemplates contains templateId /// diff --git a/src/Umbraco.Core/Models/Mapping/ContentTypeMapDefinition.cs b/src/Umbraco.Core/Models/Mapping/ContentTypeMapDefinition.cs index 3281701c84d3..debaa976c510 100644 --- a/src/Umbraco.Core/Models/Mapping/ContentTypeMapDefinition.cs +++ b/src/Umbraco.Core/Models/Mapping/ContentTypeMapDefinition.cs @@ -45,9 +45,10 @@ public ContentTypeMapDefinition(CommonMapper commonMapper, PropertyEditorCollect IMemberTypeService memberTypeService, ILoggerFactory loggerFactory, IShortStringHelper shortStringHelper, IOptions globalSettings, IHostingEnvironment hostingEnvironment) - : this(commonMapper, propertyEditors, dataTypeService, fileService, contentTypeService, mediaTypeService, memberTypeService, loggerFactory, shortStringHelper, globalSettings, hostingEnvironment, StaticServiceProvider.Instance.GetRequiredService>()) + : this(commonMapper, propertyEditors, dataTypeService, fileService, contentTypeService, mediaTypeService, + memberTypeService, loggerFactory, shortStringHelper, globalSettings, hostingEnvironment, + StaticServiceProvider.Instance.GetRequiredService>()) { - } public ContentTypeMapDefinition(CommonMapper commonMapper, PropertyEditorCollection propertyEditors, @@ -130,7 +131,10 @@ private void Map(DocumentTypeSave source, IContentType target, MapperContext con MapSaveToTypeBase(source, target, context); MapComposition(source, target, alias => _contentTypeService.Get(alias)); - target.HistoryCleanup = source.HistoryCleanup; + if (target is IContentTypeWithHistoryCleanup targetWithHistoryCleanup) + { + targetWithHistoryCleanup.HistoryCleanup = source.HistoryCleanup; + } target.AllowedTemplates = source.AllowedTemplates .Where(x => x != null) @@ -177,15 +181,23 @@ private void Map(IContentType source, DocumentTypeDisplay target, MapperContext { MapTypeToDisplayBase(source, target); - target.HistoryCleanup = new HistoryCleanupViewModel + if (source is IContentTypeWithHistoryCleanup sourceWithHistoryCleanup) { - PreventCleanup = source.HistoryCleanup.PreventCleanup, - KeepAllVersionsNewerThanDays = source.HistoryCleanup.KeepAllVersionsNewerThanDays, - KeepLatestVersionPerDayForDays = source.HistoryCleanup.KeepLatestVersionPerDayForDays, - GlobalKeepAllVersionsNewerThanDays = _contentSettings.ContentVersionCleanupPolicy.KeepAllVersionsNewerThanDays, - GlobalKeepLatestVersionPerDayForDays = _contentSettings.ContentVersionCleanupPolicy.KeepLatestVersionPerDayForDays, - GlobalEnableCleanup = _contentSettings.ContentVersionCleanupPolicy.EnableCleanup - }; + target.HistoryCleanup = new HistoryCleanupViewModel + { + PreventCleanup = sourceWithHistoryCleanup.HistoryCleanup.PreventCleanup, + KeepAllVersionsNewerThanDays = + sourceWithHistoryCleanup.HistoryCleanup.KeepAllVersionsNewerThanDays, + KeepLatestVersionPerDayForDays = + sourceWithHistoryCleanup.HistoryCleanup.KeepLatestVersionPerDayForDays, + GlobalKeepAllVersionsNewerThanDays = + _contentSettings.ContentVersionCleanupPolicy.KeepAllVersionsNewerThanDays, + GlobalKeepLatestVersionPerDayForDays = + _contentSettings.ContentVersionCleanupPolicy.KeepLatestVersionPerDayForDays, + GlobalEnableCleanup = _contentSettings.ContentVersionCleanupPolicy.EnableCleanup + }; + } + target.AllowCultureVariant = source.VariesByCulture(); target.AllowSegmentVariant = source.VariesBySegment(); diff --git a/src/Umbraco.Core/Persistence/Repositories/IDocumentVersionRepository.cs b/src/Umbraco.Core/Persistence/Repositories/IDocumentVersionRepository.cs index bcdf4f8aebeb..8175ba0d99a3 100644 --- a/src/Umbraco.Core/Persistence/Repositories/IDocumentVersionRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/IDocumentVersionRepository.cs @@ -1,9 +1,7 @@ using System.Collections.Generic; using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Persistence; -using Umbraco.Core.Models; -namespace Umbraco.Core.Persistence.Repositories +namespace Umbraco.Cms.Core.Persistence.Repositories { public interface IDocumentVersionRepository : IRepository { diff --git a/src/Umbraco.Core/Services/IContentVersionCleanupPolicy.cs b/src/Umbraco.Core/Services/IContentVersionCleanupPolicy.cs index 43718c801ffd..d2f70206b087 100644 --- a/src/Umbraco.Core/Services/IContentVersionCleanupPolicy.cs +++ b/src/Umbraco.Core/Services/IContentVersionCleanupPolicy.cs @@ -1,9 +1,8 @@ using System; using System.Collections.Generic; using Umbraco.Cms.Core.Models; -using Umbraco.Core.Models; -namespace Umbraco.Core.Services +namespace Umbraco.Cms.Core.Services { /// /// Used to filter historic content versions for cleanup. diff --git a/src/Umbraco.Core/Services/IContentVersionService.cs b/src/Umbraco.Core/Services/IContentVersionService.cs index 656fd899348d..882618780fe6 100644 --- a/src/Umbraco.Core/Services/IContentVersionService.cs +++ b/src/Umbraco.Core/Services/IContentVersionService.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using Umbraco.Cms.Core.Models; -using Umbraco.Core.Models; namespace Umbraco.Cms.Core.Services { diff --git a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Repositories.cs b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Repositories.cs index 360e7859068c..d3ebb28f9c53 100644 --- a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Repositories.cs +++ b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Repositories.cs @@ -25,6 +25,7 @@ internal static IUmbracoBuilder AddRepositories(this IUmbracoBuilder builder) builder.Services.AddUnique(); builder.Services.AddUnique(); builder.Services.AddUnique(); + builder.Services.AddUnique(); builder.Services.AddUnique(); builder.Services.AddUnique(); builder.Services.AddUnique(); diff --git a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Services.cs b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Services.cs index c7a66373f7bf..661ed9329292 100644 --- a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Services.cs +++ b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Services.cs @@ -6,7 +6,6 @@ using Microsoft.Extensions.Options; using Umbraco.Cms.Core; using Umbraco.Cms.Core.Cache; -using Umbraco.Cms.Core.Configuration; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Hosting; @@ -16,6 +15,7 @@ using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Services.Implement; using Umbraco.Cms.Infrastructure.Packaging; +using Umbraco.Cms.Infrastructure.Services.Implement; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.DependencyInjection @@ -44,6 +44,7 @@ internal static IUmbracoBuilder AddServices(this IUmbracoBuilder builder) builder.Services.AddUnique(); builder.Services.AddUnique(); builder.Services.AddUnique(); + builder.Services.AddUnique(); builder.Services.AddUnique(); builder.Services.AddUnique(); builder.Services.AddUnique(); diff --git a/src/Umbraco.Infrastructure/HostedServices/ContentVersionCleanup.cs b/src/Umbraco.Infrastructure/HostedServices/ContentVersionCleanup.cs index 6c97f7c80fd8..f486275d7625 100644 --- a/src/Umbraco.Infrastructure/HostedServices/ContentVersionCleanup.cs +++ b/src/Umbraco.Infrastructure/HostedServices/ContentVersionCleanup.cs @@ -7,7 +7,6 @@ using Umbraco.Cms.Core.Runtime; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Sync; -using Umbraco.Core.Services; namespace Umbraco.Cms.Infrastructure.HostedServices { @@ -18,10 +17,10 @@ public class ContentVersionCleanup : RecurringHostedServiceBase { private readonly IRuntimeState _runtimeState; private readonly ILogger _logger; + private readonly IOptionsMonitor _settingsMonitor; private readonly IContentVersionService _service; private readonly IMainDom _mainDom; private readonly IServerRoleAccessor _serverRoleAccessor; - private ContentVersionCleanupPolicySettings _settings; /// /// Initializes a new instance of the class. @@ -29,7 +28,7 @@ public class ContentVersionCleanup : RecurringHostedServiceBase public ContentVersionCleanup( IRuntimeState runtimeState, ILogger logger, - IOptionsMonitor settings, + IOptionsMonitor settingsMonitor, IContentVersionService service, IMainDom mainDom, IServerRoleAccessor serverRoleAccessor) @@ -37,19 +36,17 @@ public ContentVersionCleanup( { _runtimeState = runtimeState; _logger = logger; - _settings = settings.CurrentValue.ContentVersionCleanupPolicy; + _settingsMonitor = settingsMonitor; _service = service; _mainDom = mainDom; _serverRoleAccessor = serverRoleAccessor; - - settings.OnChange(x => _settings = x.ContentVersionCleanupPolicy); } /// public override Task PerformExecuteAsync(object state) { // Globally disabled by feature flag - if (!_settings.EnableCleanup) + if (!_settingsMonitor.CurrentValue.ContentVersionCleanupPolicy.EnableCleanup) { _logger.LogInformation("ContentVersionCleanup task will not run as it has been globally disabled via configuration"); return Task.CompletedTask; diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs index 2e33ab044442..76a67fd33078 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs @@ -13,7 +13,7 @@ using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_7_0; using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_9_0; using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_0_0; -using Umbraco.Core.Migrations.Upgrade.V_9_1_0; +using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_1_0; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_1_0/AddContentVersionCleanupFeature.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_1_0/AddContentVersionCleanupFeature.cs index b9729e53f034..aa0d4472e813 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_1_0/AddContentVersionCleanupFeature.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_1_0/AddContentVersionCleanupFeature.cs @@ -2,7 +2,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Extensions; -namespace Umbraco.Core.Migrations.Upgrade.V_9_1_0 +namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_1_0 { class AddContentVersionCleanupFeature : MigrationBase { diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepository.cs index 9a1ea90f6012..9fa9207f53f0 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepository.cs @@ -296,15 +296,19 @@ protected override void PersistUpdatedItem(IContentType entity) private void PersistHistoryCleanup(IContentType entity) { - ContentVersionCleanupPolicyDto dto = new ContentVersionCleanupPolicyDto() + if (entity is IContentTypeWithHistoryCleanup entityWithHistoryCleanup) { - ContentTypeId = entity.Id, - Updated = DateTime.Now, - PreventCleanup = entity.HistoryCleanup.PreventCleanup, - KeepAllVersionsNewerThanDays = entity.HistoryCleanup.KeepAllVersionsNewerThanDays, - KeepLatestVersionPerDayForDays = entity.HistoryCleanup.KeepLatestVersionPerDayForDays, - }; - Database.InsertOrUpdate(dto); + ContentVersionCleanupPolicyDto dto = new ContentVersionCleanupPolicyDto() + { + ContentTypeId = entity.Id, + Updated = DateTime.Now, + PreventCleanup = entityWithHistoryCleanup.HistoryCleanup.PreventCleanup, + KeepAllVersionsNewerThanDays = entityWithHistoryCleanup.HistoryCleanup.KeepAllVersionsNewerThanDays, + KeepLatestVersionPerDayForDays = entityWithHistoryCleanup.HistoryCleanup.KeepLatestVersionPerDayForDays, + }; + Database.InsertOrUpdate(dto); + } + } } } diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentVersionRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentVersionRepository.cs index 1067637f401c..5040ee5d7a70 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentVersionRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentVersionRepository.cs @@ -3,10 +3,9 @@ using System.Linq; using Umbraco.Cms.Core; using Umbraco.Cms.Core.Models; +using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Dtos; -using Umbraco.Core.Models; -using Umbraco.Core.Persistence.Repositories; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Services/Implement/ContentVersionService.cs b/src/Umbraco.Infrastructure/Services/Implement/ContentVersionService.cs index c8ce9ce707a7..40c12a1fe53c 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/ContentVersionService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/ContentVersionService.cs @@ -7,8 +7,6 @@ using Umbraco.Cms.Core.Notifications; using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Core.Scoping; -using Umbraco.Core.Persistence.Repositories; -using Umbraco.Core.Services; using Umbraco.Extensions; namespace Umbraco.Cms.Core.Services.Implement diff --git a/src/Umbraco.Infrastructure/Services/Implement/DefaultContentVersionCleanupPolicy.cs b/src/Umbraco.Infrastructure/Services/Implement/DefaultContentVersionCleanupPolicy.cs index 755d30306ba2..383554c34c68 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/DefaultContentVersionCleanupPolicy.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/DefaultContentVersionCleanupPolicy.cs @@ -4,11 +4,10 @@ using Microsoft.Extensions.Options; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Models; +using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Core.Scoping; -using Umbraco.Core.Models; -using Umbraco.Core.Persistence.Repositories; -using Umbraco.Core.Services; -using ContentVersionCleanupPolicySettings = Umbraco.Core.Models.ContentVersionCleanupPolicySettings; +using Umbraco.Cms.Core.Services; +using ContentVersionCleanupPolicySettings = Umbraco.Cms.Core.Models.ContentVersionCleanupPolicySettings; namespace Umbraco.Cms.Infrastructure.Services.Implement { diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DocumentVersionRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DocumentVersionRepositoryTest.cs index 6ac6fd406069..1649aa2fc6bd 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DocumentVersionRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DocumentVersionRepositoryTest.cs @@ -1,6 +1,7 @@ using System.Diagnostics; using System.Linq; using NUnit.Framework; +using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; @@ -25,8 +26,11 @@ public class DocumentVersionRepositoryTest : UmbracoIntegrationTest [Test] public void GetDocumentVersionsEligibleForCleanup_Always_ExcludesActiveVersions() { - var contentType = ContentTypeBuilder.CreateSimpleContentType("umbTextpage", "Textpage"); - FileService.SaveTemplate(contentType.DefaultTemplate); + Template template = TemplateBuilder.CreateTextPageTemplate(); + FileService.SaveTemplate(template); + + var contentType = ContentTypeBuilder.CreateSimpleContentType("umbTextpage", "Textpage", defaultTemplateId: template.Id); + ContentTypeService.Save(contentType); ContentTypeService.Save(contentType); var content = ContentBuilder.CreateSimpleContent(contentType); @@ -53,8 +57,11 @@ public void GetDocumentVersionsEligibleForCleanup_Always_ExcludesActiveVersions( [Test] public void GetDocumentVersionsEligibleForCleanup_Always_ExcludesPinnedVersions() { - var contentType = ContentTypeBuilder.CreateSimpleContentType("umbTextpage", "Textpage"); - FileService.SaveTemplate(contentType.DefaultTemplate); + Template template = TemplateBuilder.CreateTextPageTemplate(); + FileService.SaveTemplate(template); + + var contentType = ContentTypeBuilder.CreateSimpleContentType("umbTextpage", "Textpage", defaultTemplateId: template.Id); + ContentTypeService.Save(contentType); ContentTypeService.Save(contentType); var content = ContentBuilder.CreateSimpleContent(contentType); @@ -92,8 +99,10 @@ public void GetDocumentVersionsEligibleForCleanup_Always_ExcludesPinnedVersions( [Test] public void DeleteVersions_Always_DeletesSpecifiedVersions() { - var contentType = ContentTypeBuilder.CreateSimpleContentType("umbTextpage", "Textpage"); - FileService.SaveTemplate(contentType.DefaultTemplate); + Template template = TemplateBuilder.CreateTextPageTemplate(); + FileService.SaveTemplate(template); + + var contentType = ContentTypeBuilder.CreateSimpleContentType("umbTextpage", "Textpage", defaultTemplateId: template.Id); ContentTypeService.Save(contentType); var content = ContentBuilder.CreateSimpleContent(contentType); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentVersionCleanupServiceTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentVersionCleanupServiceTest.cs index 1a03482fb6c0..0f7ec616f7bd 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentVersionCleanupServiceTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentVersionCleanupServiceTest.cs @@ -20,6 +20,7 @@ internal class ContentVersionCleanupServiceTest : UmbracoIntegrationTest public IContentTypeService ContentTypeService => GetRequiredService(); public IContentService ContentService => GetRequiredService(); + public IContentVersionService ContentVersionService => GetRequiredService(); /// /// This is covered by the unit tests, but nice to know it deletes on infra. @@ -33,8 +34,10 @@ public void PerformContentVersionCleanup_WithNoKeepPeriods_DeletesEverythingExce // With 200K Versions // With 11M Property data - ContentType contentTypeA = ContentTypeBuilder.CreateSimpleContentType("contentTypeA", "contentTypeA"); - FileService.SaveTemplate(contentTypeA.DefaultTemplate); + Template template = TemplateBuilder.CreateTextPageTemplate(); + FileService.SaveTemplate(template); + + ContentType contentTypeA = ContentTypeBuilder.CreateSimpleContentType("contentTypeA", "contentTypeA", defaultTemplateId: template.Id); ContentTypeService.Save(contentTypeA); Content content = ContentBuilder.CreateSimpleContent(contentTypeA); @@ -53,7 +56,7 @@ public void PerformContentVersionCleanup_WithNoKeepPeriods_DeletesEverythingExce // Kill all historic InsertCleanupPolicy(contentTypeA, 0, 0); - ((IContentVersionService)ContentService).PerformContentVersionCleanup(DateTime.Now.AddHours(1)); + ContentVersionService.PerformContentVersionCleanup(DateTime.Now.AddHours(1)); Report after = GetReport(); diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Scheduling/ContentVersionCleanupTest.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Scheduling/ContentVersionCleanupTest.cs index 040c5059b072..ad06bc2683af 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Scheduling/ContentVersionCleanupTest.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Scheduling/ContentVersionCleanupTest.cs @@ -19,15 +19,20 @@ class ContentVersionCleanupTest { [Test, AutoMoqData] public async Task ContentVersionCleanup_WhenNotEnabled_DoesNotCleanupWillRepeat( - [Frozen] Mock> settings, + [Frozen] Mock> settings, [Frozen] Mock mainDom, [Frozen] Mock serverRoleAccessor, [Frozen] Mock runtimeState, [Frozen] Mock cleanupService, ContentVersionCleanup sut) { - settings.Setup(x => x.Value.ContentVersionCleanupPolicy.EnableCleanup).Returns(false); - + settings.Setup(x => x.CurrentValue).Returns(new ContentSettings() + { + ContentVersionCleanupPolicy = new ContentVersionCleanupPolicySettings() + { + EnableCleanup = false + } + }); runtimeState.Setup(x => x.Level).Returns(RuntimeLevel.Run); mainDom.Setup(x => x.IsMainDom).Returns(true); serverRoleAccessor.Setup(x => x.CurrentServerRole).Returns(ServerRole.SchedulingPublisher); @@ -39,14 +44,20 @@ public async Task ContentVersionCleanup_WhenNotEnabled_DoesNotCleanupWillRepeat( [Test, AutoMoqData] public async Task ContentVersionCleanup_RuntimeLevelNotRun_DoesNotCleanupWillRepeat( - [Frozen] Mock> settings, + [Frozen] Mock> settings, [Frozen] Mock mainDom, [Frozen] Mock serverRoleAccessor, [Frozen] Mock runtimeState, [Frozen] Mock cleanupService, ContentVersionCleanup sut) { - settings.Setup(x => x.Value.ContentVersionCleanupPolicy.EnableCleanup).Returns(true); + settings.Setup(x => x.CurrentValue).Returns(new ContentSettings() + { + ContentVersionCleanupPolicy = new ContentVersionCleanupPolicySettings() + { + EnableCleanup = true + } + }); runtimeState.Setup(x => x.Level).Returns(RuntimeLevel.Unknown); mainDom.Setup(x => x.IsMainDom).Returns(true); serverRoleAccessor.Setup(x => x.CurrentServerRole).Returns(ServerRole.SchedulingPublisher); @@ -58,14 +69,20 @@ public async Task ContentVersionCleanup_RuntimeLevelNotRun_DoesNotCleanupWillRep [Test, AutoMoqData] public async Task ContentVersionCleanup_ServerRoleUnknown_DoesNotCleanupWillRepeat( - [Frozen] Mock> settings, + [Frozen] Mock> settings, [Frozen] Mock mainDom, [Frozen] Mock serverRoleAccessor, [Frozen] Mock runtimeState, [Frozen] Mock cleanupService, ContentVersionCleanup sut) { - settings.Setup(x => x.Value.ContentVersionCleanupPolicy.EnableCleanup).Returns(true); + settings.Setup(x => x.CurrentValue).Returns(new ContentSettings() + { + ContentVersionCleanupPolicy = new ContentVersionCleanupPolicySettings() + { + EnableCleanup = true + } + }); runtimeState.Setup(x => x.Level).Returns(RuntimeLevel.Run); mainDom.Setup(x => x.IsMainDom).Returns(true); serverRoleAccessor.Setup(x => x.CurrentServerRole).Returns(ServerRole.Unknown); @@ -77,14 +94,21 @@ public async Task ContentVersionCleanup_ServerRoleUnknown_DoesNotCleanupWillRep [Test, AutoMoqData] public async Task ContentVersionCleanup_NotMainDom_DoesNotCleanupWillNotRepeat( - [Frozen] Mock> settings, + [Frozen] Mock> settings, [Frozen] Mock mainDom, [Frozen] Mock serverRoleAccessor, [Frozen] Mock runtimeState, [Frozen] Mock cleanupService, ContentVersionCleanup sut) { - settings.Setup(x => x.Value.ContentVersionCleanupPolicy.EnableCleanup).Returns(true); + settings.Setup(x => x.CurrentValue).Returns(new ContentSettings() + { + ContentVersionCleanupPolicy = new ContentVersionCleanupPolicySettings() + { + EnableCleanup = true + } + }); + runtimeState.Setup(x => x.Level).Returns(RuntimeLevel.Run); mainDom.Setup(x => x.IsMainDom).Returns(false); serverRoleAccessor.Setup(x => x.CurrentServerRole).Returns(ServerRole.SchedulingPublisher); @@ -96,14 +120,21 @@ public async Task ContentVersionCleanup_NotMainDom_DoesNotCleanupWillNotRepeat( [Test, AutoMoqData] public async Task ContentVersionCleanup_Enabled_DelegatesToCleanupService( - [Frozen] Mock> settings, + [Frozen] Mock> settings, [Frozen] Mock mainDom, [Frozen] Mock serverRoleAccessor, [Frozen] Mock runtimeState, [Frozen] Mock cleanupService, ContentVersionCleanup sut) { - settings.Setup(x => x.Value.ContentVersionCleanupPolicy.EnableCleanup).Returns(true); + settings.Setup(x => x.CurrentValue).Returns(new ContentSettings() + { + ContentVersionCleanupPolicy = new ContentVersionCleanupPolicySettings() + { + EnableCleanup = true + } + }); + runtimeState.Setup(x => x.Level).Returns(RuntimeLevel.Run); mainDom.Setup(x => x.IsMainDom).Returns(true); serverRoleAccessor.Setup(x => x.CurrentServerRole).Returns(ServerRole.SchedulingPublisher); diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/DefaultContentVersionCleanupPolicyTest.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/DefaultContentVersionCleanupPolicyTest.cs index a51c77c03a3b..800bcd65b798 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/DefaultContentVersionCleanupPolicyTest.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/DefaultContentVersionCleanupPolicyTest.cs @@ -7,10 +7,10 @@ using NUnit.Framework; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Models; +using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Infrastructure.Services.Implement; using Umbraco.Cms.Tests.UnitTests.AutoFixture; -using Umbraco.Core.Persistence.Repositories; -using ContentVersionCleanupPolicySettings = Umbraco.Core.Models.ContentVersionCleanupPolicySettings; +using ContentVersionCleanupPolicySettings = Umbraco.Cms.Core.Models.ContentVersionCleanupPolicySettings; namespace Umbraco.Tests.Services { @@ -31,9 +31,15 @@ public void Apply_AllOlderThanKeepSettings_AllVersionsReturned( new HistoricContentVersionMeta(versionId: ++versionId, contentId: 1, contentTypeId: 1, versionDate: DateTime.Today.AddHours(-1)), }; - contentSettings.Setup(x => x.Value.ContentVersionCleanupPolicy.EnableCleanup).Returns(true); - contentSettings.Setup(x => x.Value.ContentVersionCleanupPolicy.KeepAllVersionsNewerThanDays).Returns(0); - contentSettings.Setup(x => x.Value.ContentVersionCleanupPolicy.KeepLatestVersionPerDayForDays).Returns(0); + contentSettings.Setup(x => x.Value).Returns(new ContentSettings() + { + ContentVersionCleanupPolicy = new Cms.Core.Configuration.Models.ContentVersionCleanupPolicySettings() + { + EnableCleanup = true, + KeepAllVersionsNewerThanDays = 0, + KeepLatestVersionPerDayForDays = 0 + } + }); documentVersionRepository.Setup(x => x.GetCleanupPolicies()) .Returns(Array.Empty()); @@ -60,9 +66,15 @@ public void Apply_OverlappingKeepSettings_KeepAllVersionsNewerThanDaysTakesPrior new HistoricContentVersionMeta(versionId: ++versionId, contentId: 1, contentTypeId: 1, versionDate: DateTime.Today.AddHours(-1)), }; - contentSettings.Setup(x => x.Value.ContentVersionCleanupPolicy.EnableCleanup).Returns(true); - contentSettings.Setup(x => x.Value.ContentVersionCleanupPolicy.KeepAllVersionsNewerThanDays).Returns(2); - contentSettings.Setup(x => x.Value.ContentVersionCleanupPolicy.KeepLatestVersionPerDayForDays).Returns(2); + contentSettings.Setup(x => x.Value).Returns(new ContentSettings() + { + ContentVersionCleanupPolicy = new Cms.Core.Configuration.Models.ContentVersionCleanupPolicySettings() + { + EnableCleanup = true, + KeepAllVersionsNewerThanDays = 2, + KeepLatestVersionPerDayForDays = 2 + } + }); documentVersionRepository.Setup(x => x.GetCleanupPolicies()) .Returns(Array.Empty()); @@ -96,9 +108,15 @@ public void Apply_WithinInKeepLatestPerDay_ReturnsSinglePerContentPerDay( new HistoricContentVersionMeta(versionId: 9, contentId: 2, contentTypeId: 1, versionDate: DateTime.Today.AddHours(-1)), }; - contentSettings.Setup(x => x.Value.ContentVersionCleanupPolicy.EnableCleanup).Returns(true); - contentSettings.Setup(x => x.Value.ContentVersionCleanupPolicy.KeepAllVersionsNewerThanDays).Returns(0); - contentSettings.Setup(x => x.Value.ContentVersionCleanupPolicy.KeepLatestVersionPerDayForDays).Returns(3); + contentSettings.Setup(x => x.Value).Returns(new ContentSettings() + { + ContentVersionCleanupPolicy = new Cms.Core.Configuration.Models.ContentVersionCleanupPolicySettings() + { + EnableCleanup = true, + KeepAllVersionsNewerThanDays = 0, + KeepLatestVersionPerDayForDays = 3 + } + }); documentVersionRepository.Setup(x => x.GetCleanupPolicies()) .Returns(Array.Empty()); @@ -134,9 +152,15 @@ public void Apply_HasOverridePolicy_RespectsPreventCleanup( new HistoricContentVersionMeta(versionId: 6, contentId: 2, contentTypeId: 2, versionDate: DateTime.Today.AddHours(-1)), }; - contentSettings.Setup(x => x.Value.ContentVersionCleanupPolicy.EnableCleanup).Returns(true); - contentSettings.Setup(x => x.Value.ContentVersionCleanupPolicy.KeepAllVersionsNewerThanDays).Returns(0); - contentSettings.Setup(x => x.Value.ContentVersionCleanupPolicy.KeepLatestVersionPerDayForDays).Returns(0); + contentSettings.Setup(x => x.Value).Returns(new ContentSettings() + { + ContentVersionCleanupPolicy = new Cms.Core.Configuration.Models.ContentVersionCleanupPolicySettings() + { + EnableCleanup = true, + KeepAllVersionsNewerThanDays = 0, + KeepLatestVersionPerDayForDays = 0 + } + }); documentVersionRepository.Setup(x => x.GetCleanupPolicies()) .Returns(new ContentVersionCleanupPolicySettings[] @@ -169,9 +193,15 @@ public void Apply_HasOverridePolicy_RespectsKeepAll( new HistoricContentVersionMeta(versionId: 6, contentId: 2, contentTypeId: 2, versionDate: DateTime.Today.AddHours(-1)), }; - contentSettings.Setup(x => x.Value.ContentVersionCleanupPolicy.EnableCleanup).Returns(true); - contentSettings.Setup(x => x.Value.ContentVersionCleanupPolicy.KeepAllVersionsNewerThanDays).Returns(0); - contentSettings.Setup(x => x.Value.ContentVersionCleanupPolicy.KeepLatestVersionPerDayForDays).Returns(0); + contentSettings.Setup(x => x.Value).Returns(new ContentSettings() + { + ContentVersionCleanupPolicy = new Cms.Core.Configuration.Models.ContentVersionCleanupPolicySettings() + { + EnableCleanup = true, + KeepAllVersionsNewerThanDays = 0, + KeepLatestVersionPerDayForDays = 0 + } + }); documentVersionRepository.Setup(x => x.GetCleanupPolicies()) .Returns(new ContentVersionCleanupPolicySettings[] @@ -204,9 +234,15 @@ public void Apply_HasOverridePolicy_RespectsKeepLatest( new HistoricContentVersionMeta(versionId: 6, contentId: 2, contentTypeId: 2, versionDate: DateTime.Today.AddHours(-1)), }; - contentSettings.Setup(x => x.Value.ContentVersionCleanupPolicy.EnableCleanup).Returns(true); - contentSettings.Setup(x => x.Value.ContentVersionCleanupPolicy.KeepAllVersionsNewerThanDays).Returns(0); - contentSettings.Setup(x => x.Value.ContentVersionCleanupPolicy.KeepLatestVersionPerDayForDays).Returns(0); + contentSettings.Setup(x => x.Value).Returns(new ContentSettings() + { + ContentVersionCleanupPolicy = new Cms.Core.Configuration.Models.ContentVersionCleanupPolicySettings() + { + EnableCleanup = true, + KeepAllVersionsNewerThanDays = 0, + KeepLatestVersionPerDayForDays = 0 + } + }); documentVersionRepository.Setup(x => x.GetCleanupPolicies()) .Returns(new ContentVersionCleanupPolicySettings[]