From 236bf881434cb30eb2f43c3ea511cfff0839f4c6 Mon Sep 17 00:00:00 2001 From: Elitsa Marinovska Date: Wed, 3 Nov 2021 10:23:50 +0100 Subject: [PATCH] Cleanup --- .../ContentEditing/DocumentTypeDisplay.cs | 11 +++++++---- .../Models/ContentEditing/HistoryCleanup.cs | 3 ++- .../ContentEditing/HistoryCleanupViewModel.cs | 11 ++++++----- src/Umbraco.Core/Models/ContentType.cs | 10 ++++------ .../ContentVersionCleanupPolicySettings.cs | 6 +++++- src/Umbraco.Core/Models/IContentType.cs | 3 +-- .../Dtos/ContentVersionCleanupPolicyDto.cs | 7 +++---- .../Implement/ContentTypeRepository.cs | 4 ++-- .../Services/Implement/ContentService.cs | 19 ++++++++++--------- .../services/umbdataformatter.service.js | 2 +- .../ContentVersionCleanupServiceTest.cs | 5 +++-- .../Scheduling/ContentVersionCleanupTest.cs | 1 - .../DefaultContentVersionCleanupPolicyTest.cs | 1 - .../Controllers/MemberControllerUnitTests.cs | 3 +-- 14 files changed, 45 insertions(+), 41 deletions(-) diff --git a/src/Umbraco.Core/Models/ContentEditing/DocumentTypeDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/DocumentTypeDisplay.cs index 1fa0895f61e1..3bb52c39b724 100644 --- a/src/Umbraco.Core/Models/ContentEditing/DocumentTypeDisplay.cs +++ b/src/Umbraco.Core/Models/ContentEditing/DocumentTypeDisplay.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Runtime.Serialization; namespace Umbraco.Cms.Core.Models.ContentEditing @@ -16,7 +16,8 @@ public DocumentTypeDisplay() => [DataMember(Name = "allowedTemplates")] public IEnumerable AllowedTemplates { get; set; } - [DataMember(Name = "defaultTemplate")] public EntityBasic DefaultTemplate { get; set; } + [DataMember(Name = "defaultTemplate")] + public EntityBasic DefaultTemplate { get; set; } [DataMember(Name = "allowCultureVariant")] public bool AllowCultureVariant { get; set; } @@ -24,8 +25,10 @@ public DocumentTypeDisplay() => [DataMember(Name = "allowSegmentVariant")] public bool AllowSegmentVariant { get; set; } - [DataMember(Name = "apps")] public IEnumerable ContentApps { get; set; } + [DataMember(Name = "apps")] + public IEnumerable ContentApps { get; set; } - [DataMember(Name = "historyCleanup")] public HistoryCleanupViewModel HistoryCleanup { get; set; } + [DataMember(Name = "historyCleanup")] + public HistoryCleanupViewModel HistoryCleanup { get; set; } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/HistoryCleanup.cs b/src/Umbraco.Core/Models/ContentEditing/HistoryCleanup.cs index 5e7b34b0bf0c..b7bfb328087f 100644 --- a/src/Umbraco.Core/Models/ContentEditing/HistoryCleanup.cs +++ b/src/Umbraco.Core/Models/ContentEditing/HistoryCleanup.cs @@ -5,7 +5,8 @@ namespace Umbraco.Cms.Core.Models.ContentEditing [DataContract(Name = "historyCleanup", Namespace = "")] public class HistoryCleanup { - [DataMember(Name = "preventCleanup")] public bool PreventCleanup { get; set; } + [DataMember(Name = "preventCleanup")] + public bool PreventCleanup { get; set; } [DataMember(Name = "keepAllVersionsNewerThanDays")] public int? KeepAllVersionsNewerThanDays { get; set; } diff --git a/src/Umbraco.Core/Models/ContentEditing/HistoryCleanupViewModel.cs b/src/Umbraco.Core/Models/ContentEditing/HistoryCleanupViewModel.cs index 94423a80606e..303ff4eda375 100644 --- a/src/Umbraco.Core/Models/ContentEditing/HistoryCleanupViewModel.cs +++ b/src/Umbraco.Core/Models/ContentEditing/HistoryCleanupViewModel.cs @@ -5,13 +5,14 @@ namespace Umbraco.Cms.Core.Models.ContentEditing [DataContract(Name = "historyCleanup", Namespace = "")] public class HistoryCleanupViewModel : HistoryCleanup { - [DataMember(Name = "globalKeepAllVersionsNewerThanDays")] - public int? GlobalKeepAllVersionsNewerThanDays { get;set; } - - [DataMember(Name = "globalKeepLatestVersionPerDayForDays")] - public int? GlobalKeepLatestVersionPerDayForDays { get; set;} [DataMember(Name = "globalEnableCleanup")] public bool GlobalEnableCleanup { get; set; } + + [DataMember(Name = "globalKeepAllVersionsNewerThanDays")] + public int? GlobalKeepAllVersionsNewerThanDays { get; set; } + + [DataMember(Name = "globalKeepLatestVersionPerDayForDays")] + public int? GlobalKeepLatestVersionPerDayForDays { get; set; } } } diff --git a/src/Umbraco.Core/Models/ContentType.cs b/src/Umbraco.Core/Models/ContentType.cs index a2357e21ef49..6ff94f57f363 100644 --- a/src/Umbraco.Core/Models/ContentType.cs +++ b/src/Umbraco.Core/Models/ContentType.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; @@ -17,9 +17,8 @@ public class ContentType : ContentTypeCompositionBase, IContentTypeWithHistoryCl { public const bool SupportsPublishingConst = true; - - //Custom comparer for enumerable - private static readonly DelegateEqualityComparer> TemplateComparer = new( + // Custom comparer for enumerable + private static readonly DelegateEqualityComparer> TemplateComparer = new ( (templates, enumerable) => templates.UnsortedSequenceEqual(enumerable), templates => templates.GetHashCode()); @@ -88,8 +87,7 @@ public IEnumerable AllowedTemplates get => _allowedTemplates; set { - SetPropertyValueAndDetectChanges(value, ref _allowedTemplates, nameof(AllowedTemplates), - TemplateComparer); + SetPropertyValueAndDetectChanges(value, ref _allowedTemplates, nameof(AllowedTemplates), TemplateComparer); if (_allowedTemplates.Any(x => x.Id == _defaultTemplate) == false) { diff --git a/src/Umbraco.Core/Models/ContentVersionCleanupPolicySettings.cs b/src/Umbraco.Core/Models/ContentVersionCleanupPolicySettings.cs index b23e6c95fae5..5fa0e9895822 100644 --- a/src/Umbraco.Core/Models/ContentVersionCleanupPolicySettings.cs +++ b/src/Umbraco.Core/Models/ContentVersionCleanupPolicySettings.cs @@ -5,9 +5,13 @@ namespace Umbraco.Cms.Core.Models public class ContentVersionCleanupPolicySettings { public int ContentTypeId { get; set; } + + public bool PreventCleanup { get; set; } + public int? KeepAllVersionsNewerThanDays { get; set; } + public int? KeepLatestVersionPerDayForDays { get; set; } - public bool PreventCleanup { get; set; } + public DateTime Updated { get; set; } } } diff --git a/src/Umbraco.Core/Models/IContentType.cs b/src/Umbraco.Core/Models/IContentType.cs index 4025239a3fde..a01e6128878b 100644 --- a/src/Umbraco.Core/Models/IContentType.cs +++ b/src/Umbraco.Core/Models/IContentType.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using Umbraco.Cms.Core.Models.ContentEditing; @@ -13,7 +13,6 @@ public interface IContentTypeWithHistoryCleanup : IContentType HistoryCleanup HistoryCleanup { get; set; } } - /// /// Defines a ContentType, which Content is based on /// diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/ContentVersionCleanupPolicyDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/ContentVersionCleanupPolicyDto.cs index f0350d9f1bee..4b2faa166f5b 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/ContentVersionCleanupPolicyDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/ContentVersionCleanupPolicyDto.cs @@ -4,7 +4,6 @@ using Umbraco.Cms.Core; using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations; - namespace Umbraco.Cms.Infrastructure.Persistence.Dtos { [TableName(TableName)] @@ -18,6 +17,9 @@ internal class ContentVersionCleanupPolicyDto [ForeignKey(typeof(ContentTypeDto), Column = "nodeId", OnDelete = Rule.Cascade)] public int ContentTypeId { get; set; } + [Column("preventCleanup")] + public bool PreventCleanup { get; set; } + [Column("keepAllVersionsNewerThanDays")] [NullSetting(NullSetting = NullSettings.Null)] public int? KeepAllVersionsNewerThanDays { get; set; } @@ -26,9 +28,6 @@ internal class ContentVersionCleanupPolicyDto [NullSetting(NullSetting = NullSettings.Null)] public int? KeepLatestVersionPerDayForDays { get; set; } - [Column("preventCleanup")] - public bool PreventCleanup { get; set; } - [Column("updated")] public DateTime Updated { get; set; } } diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepository.cs index 0df72cd2f6ef..6ab97c971f8b 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using Microsoft.Extensions.Logging; @@ -305,7 +305,7 @@ private void PersistHistoryCleanup(IContentType entity) Updated = DateTime.Now, PreventCleanup = entityWithHistoryCleanup.HistoryCleanup.PreventCleanup, KeepAllVersionsNewerThanDays = entityWithHistoryCleanup.HistoryCleanup.KeepAllVersionsNewerThanDays, - KeepLatestVersionPerDayForDays = entityWithHistoryCleanup.HistoryCleanup.KeepLatestVersionPerDayForDays, + KeepLatestVersionPerDayForDays = entityWithHistoryCleanup.HistoryCleanup.KeepLatestVersionPerDayForDays }; Database.InsertOrUpdate(dto); } diff --git a/src/Umbraco.Infrastructure/Services/Implement/ContentService.cs b/src/Umbraco.Infrastructure/Services/Implement/ContentService.cs index f8669a77b46e..04b93bdd9f51 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/ContentService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/ContentService.cs @@ -74,19 +74,19 @@ public OperationResult Rollback(int id, int versionId, string culture = "*", { EventMessages evtMsgs = EventMessagesFactory.Get(); - //Get the current copy of the node + // Get the current copy of the node IContent content = GetById(id); - //Get the version + // Get the version IContent version = GetVersion(versionId); - //Good ole null checks + // Good old null checks if (content == null || version == null || content.Trashed) { return new OperationResult(OperationResultType.FailedCannot, evtMsgs); } - //Store the result of doing the save of content for the rollback + // Store the result of doing the save of content for the rollback OperationResult rollbackSaveResult; using (IScope scope = ScopeProvider.CreateScope()) @@ -98,16 +98,16 @@ public OperationResult Rollback(int id, int versionId, string culture = "*", return OperationResult.Cancel(evtMsgs); } - //Copy the changes from the version + // Copy the changes from the version content.CopyFrom(version, culture); - //Save the content for the rollback + // Save the content for the rollback rollbackSaveResult = Save(content, userId); - //Depending on the save result - is what we log & audit along with what we return + // Depending on the save result - is what we log & audit along with what we return if (rollbackSaveResult.Success == false) { - //Log the error/warning + // Log the error/warning _logger.LogError( "User '{UserId}' was unable to rollback content '{ContentId}' to version '{VersionId}'", userId, id, versionId); @@ -117,7 +117,7 @@ public OperationResult Rollback(int id, int versionId, string culture = "*", scope.Notifications.Publish( new ContentRolledBackNotification(content, evtMsgs).WithStateFrom(rollingBackNotification)); - //Logging & Audit message + // Logging & Audit message _logger.LogInformation("User '{UserId}' rolled back content '{ContentId}' to version '{VersionId}'", userId, id, versionId); Audit(AuditType.RollBack, userId, id, @@ -1799,6 +1799,7 @@ private void PerformScheduledPublishingRelease(DateTime date, List GetRequiredService(); public IContentService ContentService => GetRequiredService(); + public IContentVersionService ContentVersionService => GetRequiredService(); /// @@ -29,7 +30,7 @@ internal class ContentVersionCleanupServiceTest : UmbracoIntegrationTest [Test] public void PerformContentVersionCleanup_WithNoKeepPeriods_DeletesEverythingExceptActive() { - // For reference currently has + // For reference, Our currently has // 5000 Documents // With 200K Versions // With 11M Property data @@ -38,12 +39,12 @@ public void PerformContentVersionCleanup_WithNoKeepPeriods_DeletesEverythingExce FileService.SaveTemplate(template); ContentType contentTypeA = ContentTypeBuilder.CreateSimpleContentType("contentTypeA", "contentTypeA", defaultTemplateId: template.Id); + // Kill all historic contentTypeA.HistoryCleanup.PreventCleanup = false; contentTypeA.HistoryCleanup.KeepAllVersionsNewerThanDays = 0; contentTypeA.HistoryCleanup.KeepLatestVersionPerDayForDays = 0; - ContentTypeService.Save(contentTypeA); Content content = ContentBuilder.CreateSimpleContent(contentTypeA); diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Scheduling/ContentVersionCleanupTest.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Scheduling/ContentVersionCleanupTest.cs index ad06bc2683af..430cd184c155 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Scheduling/ContentVersionCleanupTest.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Scheduling/ContentVersionCleanupTest.cs @@ -139,7 +139,6 @@ public async Task ContentVersionCleanup_Enabled_DelegatesToCleanupService( mainDom.Setup(x => x.IsMainDom).Returns(true); serverRoleAccessor.Setup(x => x.CurrentServerRole).Returns(ServerRole.SchedulingPublisher); - await sut.PerformExecuteAsync(null); cleanupService.Verify(x => x.PerformContentVersionCleanup(It.IsAny()), Times.Once); diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/DefaultContentVersionCleanupPolicyTest.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/DefaultContentVersionCleanupPolicyTest.cs index 800bcd65b798..db258c5fa150 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/DefaultContentVersionCleanupPolicyTest.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/DefaultContentVersionCleanupPolicyTest.cs @@ -261,6 +261,5 @@ public void Apply_HasOverridePolicy_RespectsKeepLatest( Assert.AreEqual(6, results.Single(x => x.ContentTypeId == 2).VersionId); }); } - } } diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MemberControllerUnitTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MemberControllerUnitTests.cs index b70b6ae65847..d1ce62242e6b 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MemberControllerUnitTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MemberControllerUnitTests.cs @@ -503,8 +503,7 @@ private MemberController CreateSut( mockShortStringHelper, globalSettings, new Mock().Object, - new Mock>().Object - ) + new Mock>().Object) }); var scopeProvider = Mock.Of(x => x.CreateScope( It.IsAny(),