This commit is contained in:
Elitsa Marinovska
2021-11-03 10:23:50 +01:00
parent a25183a063
commit 236bf88143
14 changed files with 46 additions and 42 deletions

View File

@@ -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 @@ namespace Umbraco.Cms.Core.Models.ContentEditing
[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; }
@@ -24,8 +25,10 @@ namespace Umbraco.Cms.Core.Models.ContentEditing
[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; }
}
}

View File

@@ -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; }

View File

@@ -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; }
}
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
@@ -17,9 +17,8 @@ namespace Umbraco.Cms.Core.Models
{
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());
@@ -88,8 +87,7 @@ namespace Umbraco.Cms.Core.Models
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)
{

View File

@@ -5,9 +5,13 @@ namespace Umbraco.Cms.Core.Models
public class ContentVersionCleanupPolicySettings
{
public int ContentTypeId { get; set; }
public int? KeepAllVersionsNewerThanDays { get; set; }
public int? KeepLatestVersionPerDayForDays { get; set; }
public bool PreventCleanup { get; set; }
public int? KeepAllVersionsNewerThanDays { get; set; }
public int? KeepLatestVersionPerDayForDays { get; set; }
public DateTime Updated { get; set; }
}
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using Umbraco.Cms.Core.Models.ContentEditing;
@@ -13,7 +13,6 @@ namespace Umbraco.Cms.Core.Models
HistoryCleanup HistoryCleanup { get; set; }
}
/// <summary>
/// Defines a ContentType, which Content is based on
/// </summary>

View File

@@ -4,7 +4,6 @@ using NPoco;
using Umbraco.Cms.Core;
using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos
{
[TableName(TableName)]
@@ -18,6 +17,9 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos
[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 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos
[NullSetting(NullSetting = NullSettings.Null)]
public int? KeepLatestVersionPerDayForDays { get; set; }
[Column("preventCleanup")]
public bool PreventCleanup { get; set; }
[Column("updated")]
public DateTime Updated { get; set; }
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Logging;
@@ -305,7 +305,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
Updated = DateTime.Now,
PreventCleanup = entityWithHistoryCleanup.HistoryCleanup.PreventCleanup,
KeepAllVersionsNewerThanDays = entityWithHistoryCleanup.HistoryCleanup.KeepAllVersionsNewerThanDays,
KeepLatestVersionPerDayForDays = entityWithHistoryCleanup.HistoryCleanup.KeepLatestVersionPerDayForDays,
KeepLatestVersionPerDayForDays = entityWithHistoryCleanup.HistoryCleanup.KeepLatestVersionPerDayForDays
};
Database.InsertOrUpdate(dto);
}

View File

@@ -74,19 +74,19 @@ namespace Umbraco.Cms.Core.Services.Implement
{
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 @@ namespace Umbraco.Cms.Core.Services.Implement
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 @@ namespace Umbraco.Cms.Core.Services.Implement
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 @@ namespace Umbraco.Cms.Core.Services.Implement
publishing &= tryPublish; //set the culture to be published
if (!publishing)
{
continue;
}
}

View File

@@ -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;

View File

@@ -20,6 +20,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services
public IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
public IContentService ContentService => GetRequiredService<IContentService>();
public IContentVersionService ContentVersionService => GetRequiredService<IContentVersionService>();
/// <remarks>
@@ -29,7 +30,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services
[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 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services
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);

View File

@@ -139,7 +139,6 @@ namespace Umbraco.Tests.Scheduling
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);

View File

@@ -261,6 +261,5 @@ namespace Umbraco.Tests.Services
Assert.AreEqual(6, results.Single(x => x.ContentTypeId == 2).VersionId);
});
}
}
}

View File

@@ -503,8 +503,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.BackOffice.Controllers
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>(),