Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
elit0451 committed Nov 3, 2021
1 parent a25183a commit 236bf88
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 41 deletions.
11 changes: 7 additions & 4 deletions src/Umbraco.Core/Models/ContentEditing/DocumentTypeDisplay.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace Umbraco.Cms.Core.Models.ContentEditing
Expand All @@ -16,16 +16,19 @@ public DocumentTypeDisplay() =>
[DataMember(Name = "allowedTemplates")]
public IEnumerable<EntityBasic> 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; }

[DataMember(Name = "allowSegmentVariant")]
public bool AllowSegmentVariant { get; set; }

[DataMember(Name = "apps")] public IEnumerable<ContentApp> ContentApps { get; set; }
[DataMember(Name = "apps")]
public IEnumerable<ContentApp> ContentApps { get; set; }

[DataMember(Name = "historyCleanup")] public HistoryCleanupViewModel HistoryCleanup { get; set; }
[DataMember(Name = "historyCleanup")]
public HistoryCleanupViewModel HistoryCleanup { get; set; }
}
}
3 changes: 2 additions & 1 deletion src/Umbraco.Core/Models/ContentEditing/HistoryCleanup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
10 changes: 4 additions & 6 deletions src/Umbraco.Core/Models/ContentType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
Expand All @@ -17,9 +17,8 @@ public class ContentType : ContentTypeCompositionBase, IContentTypeWithHistoryCl
{
public const bool SupportsPublishingConst = true;


//Custom comparer for enumerable
private static readonly DelegateEqualityComparer<IEnumerable<ITemplate>> TemplateComparer = new(
// Custom comparer for enumerable
private static readonly DelegateEqualityComparer<IEnumerable<ITemplate>> TemplateComparer = new (
(templates, enumerable) => templates.UnsortedSequenceEqual(enumerable),
templates => templates.GetHashCode());

Expand Down Expand Up @@ -88,8 +87,7 @@ public IEnumerable<ITemplate> 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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
3 changes: 1 addition & 2 deletions src/Umbraco.Core/Models/IContentType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using Umbraco.Cms.Core.Models.ContentEditing;

Expand All @@ -13,7 +13,6 @@ public interface IContentTypeWithHistoryCleanup : IContentType
HistoryCleanup HistoryCleanup { get; set; }
}


/// <summary>
/// Defines a ContentType, which Content is based on
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Umbraco.Cms.Core;
using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;


namespace Umbraco.Cms.Infrastructure.Persistence.Dtos
{
[TableName(TableName)]
Expand All @@ -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; }
Expand All @@ -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; }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -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);
}
Expand Down
19 changes: 10 additions & 9 deletions src/Umbraco.Infrastructure/Services/Implement/ContentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -1799,6 +1799,7 @@ private void PerformScheduledPublishingRelease(DateTime date, List<PublishResult
publishing &= tryPublish; //set the culture to be published
if (!publishing)
{
continue;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
var saveModel = _.pick(displayModel,
'compositeContentTypes', 'isContainer', 'allowAsRoot', 'allowedTemplates', 'allowedContentTypes',
'alias', 'description', 'thumbnail', 'name', 'id', 'icon', 'trashed',
'key', 'parentId', 'alias', 'path', 'allowCultureVariant', 'allowSegmentVariant', 'isElement','historyCleanup');
'key', 'parentId', 'alias', 'path', 'allowCultureVariant', 'allowSegmentVariant', 'isElement', 'historyCleanup');

saveModel.allowedTemplates = _.map(displayModel.allowedTemplates, function (t) { return t.alias; });
saveModel.defaultTemplate = displayModel.defaultTemplate ? displayModel.defaultTemplate.alias : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ internal class ContentVersionCleanupServiceTest : UmbracoIntegrationTest
public IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();

public IContentService ContentService => GetRequiredService<IContentService>();

public IContentVersionService ContentVersionService => GetRequiredService<IContentVersionService>();

/// <remarks>
Expand All @@ -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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DateTime>()), Times.Once);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,5 @@ public void Apply_HasOverridePolicy_RespectsKeepLatest(
Assert.AreEqual(6, results.Single(x => x.ContentTypeId == 2).VersionId);
});
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,7 @@ private MemberController CreateSut(
mockShortStringHelper,
globalSettings,
new Mock<IHostingEnvironment>().Object,
new Mock<IOptionsMonitor<ContentSettings>>().Object
)
new Mock<IOptionsMonitor<ContentSettings>>().Object)
});
var scopeProvider = Mock.Of<IScopeProvider>(x => x.CreateScope(
It.IsAny<IsolationLevel>(),
Expand Down

0 comments on commit 236bf88

Please sign in to comment.