Skip to content

Commit

Permalink
Merge pull request umbraco#11562 from umbraco/v9/feature/merge_and_cl…
Browse files Browse the repository at this point in the history
…ean_history_cleanup

V9: Merged History cleanup from v8 and refactored to v9
  • Loading branch information
bergmania authored Nov 3, 2021
2 parents ef4a0f8 + 53a83ab commit f694a09
Show file tree
Hide file tree
Showing 50 changed files with 5,805 additions and 1,060 deletions.
5 changes: 5 additions & 0 deletions build/templates/UmbracoProject/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
//#endif
"Hosting": {
"Debug": false
},
"Content": {
"ContentVersionCleanupPolicy": {
"EnableCleanup": true
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Umbraco.Core/Configuration/Models/ContentSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ @keyframes umbraco-preview-badge--effect {{
[DefaultValue(StaticLoginLogoImage)]
public string LoginLogoImage { get; set; } = StaticLoginLogoImage;


/// <summary>
/// Get or sets the model representing the global content version cleanup policy
/// </summary>
public ContentVersionCleanupPolicySettings ContentVersionCleanupPolicy { get; set; } = new ContentVersionCleanupPolicySettings();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.ComponentModel;

namespace Umbraco.Cms.Core.Configuration.Models
{
/// <summary>
/// Model representing the global content version cleanup policy
/// </summary>
public class ContentVersionCleanupPolicySettings
{
private const bool StaticEnableCleanup = false;
private const int StaticKeepAllVersionsNewerThanDays = 7;
private const int StaticKeepLatestVersionPerDayForDays = 90;

/// <summary>
/// Gets or sets a value indicating whether or not the cleanup job should be executed.
/// </summary>
[DefaultValue(StaticEnableCleanup)]
public bool EnableCleanup { get; set; } = StaticEnableCleanup;

/// <summary>
/// Gets or sets the number of days where all historical content versions are kept.
/// </summary>
[DefaultValue(StaticKeepAllVersionsNewerThanDays)]
public int KeepAllVersionsNewerThanDays { get; set; } = StaticKeepAllVersionsNewerThanDays;

/// <summary>
/// Gets or sets the number of days where the latest historical content version for that day are kept.
/// </summary>
[DefaultValue(StaticKeepLatestVersionPerDayForDays)]
public int KeepLatestVersionPerDayForDays { get; set; } = StaticKeepLatestVersionPerDayForDays;

}
}
3 changes: 3 additions & 0 deletions src/Umbraco.Core/Models/ContentEditing/ContentTypeSave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ protected ContentTypeSave()
[DataMember(Name = "allowedContentTypes")]
public IEnumerable<int> AllowedContentTypes { get; set; }

[DataMember(Name = "historyCleanup")]
public HistoryCleanupViewModel HistoryCleanup { get; set; }

/// <summary>
/// Custom validation
/// </summary>
Expand Down
9 changes: 5 additions & 4 deletions src/Umbraco.Core/Models/ContentEditing/DocumentTypeDisplay.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace Umbraco.Cms.Core.Models.ContentEditing
{
[DataContract(Name = "contentType", Namespace = "")]
public class DocumentTypeDisplay : ContentTypeCompositionDisplay<PropertyTypeDisplay>
{
public DocumentTypeDisplay()
{
public DocumentTypeDisplay() =>
//initialize collections so at least their never null
AllowedTemplates = new List<EntityBasic>();
}

//name, alias, icon, thumb, desc, inherited from the content type

Expand All @@ -29,5 +27,8 @@ public DocumentTypeDisplay()

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

[DataMember(Name = "historyCleanup")]
public HistoryCleanupViewModel HistoryCleanup { get; set; }
}
}
17 changes: 17 additions & 0 deletions src/Umbraco.Core/Models/ContentEditing/HistoryCleanup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Runtime.Serialization;

namespace Umbraco.Cms.Core.Models.ContentEditing
{
[DataContract(Name = "historyCleanup", Namespace = "")]
public class HistoryCleanup
{
[DataMember(Name = "preventCleanup")]
public bool PreventCleanup { get; set; }

[DataMember(Name = "keepAllVersionsNewerThanDays")]
public int? KeepAllVersionsNewerThanDays { get; set; }

[DataMember(Name = "keepLatestVersionPerDayForDays")]
public int? KeepLatestVersionPerDayForDays { get; set; }
}
}
18 changes: 18 additions & 0 deletions src/Umbraco.Core/Models/ContentEditing/HistoryCleanupViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Runtime.Serialization;

namespace Umbraco.Cms.Core.Models.ContentEditing
{
[DataContract(Name = "historyCleanup", Namespace = "")]
public class HistoryCleanupViewModel : HistoryCleanup
{

[DataMember(Name = "globalEnableCleanup")]
public bool GlobalEnableCleanup { get; set; }

[DataMember(Name = "globalKeepAllVersionsNewerThanDays")]
public int? GlobalKeepAllVersionsNewerThanDays { get; set; }

[DataMember(Name = "globalKeepLatestVersionPerDayForDays")]
public int? GlobalKeepLatestVersionPerDayForDays { get; set; }
}
}
85 changes: 45 additions & 40 deletions src/Umbraco.Core/Models/ContentType.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,45 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using Umbraco.Cms.Core.Models.ContentEditing;
using Umbraco.Cms.Core.Strings;
using Umbraco.Extensions;

namespace Umbraco.Cms.Core.Models
{
/// <summary>
/// Represents the content type that a <see cref="Content"/> object is based on
/// Represents the content type that a <see cref="Content" /> object is based on
/// </summary>
[Serializable]
[DataContract(IsReference = true)]
public class ContentType : ContentTypeCompositionBase, IContentType
public class ContentType : ContentTypeCompositionBase, IContentTypeWithHistoryCleanup
{
public const bool SupportsPublishingConst = true;

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

private IEnumerable<ITemplate> _allowedTemplates;

private int _defaultTemplate;

/// <summary>
/// Constuctor for creating a ContentType with the parent's id.
/// Constuctor for creating a ContentType with the parent's id.
/// </summary>
/// <remarks>Only use this for creating ContentTypes at the root (with ParentId -1).</remarks>
/// <param name="parentId"></param>
public ContentType(IShortStringHelper shortStringHelper, int parentId) : base(shortStringHelper, parentId)
{
_allowedTemplates = new List<ITemplate>();
HistoryCleanup = new HistoryCleanup();
}


/// <summary>
/// Constuctor for creating a ContentType with the parent as an inherited type.
/// Constuctor for creating a ContentType with the parent as an inherited type.
/// </summary>
/// <remarks>Use this to ensure inheritance from parent.</remarks>
/// <param name="parent"></param>
Expand All @@ -40,30 +48,24 @@ public ContentType(IShortStringHelper shortStringHelper, IContentType parent, st
: base(shortStringHelper, parent, alias)
{
_allowedTemplates = new List<ITemplate>();
HistoryCleanup = new HistoryCleanup();
}

/// <inheritdoc />
public override ISimpleContentType ToSimple() => new SimpleContentType(this);

/// <inheritdoc />
public override bool SupportsPublishing => SupportsPublishingConst;

//Custom comparer for enumerable
private static readonly DelegateEqualityComparer<IEnumerable<ITemplate>> TemplateComparer = new DelegateEqualityComparer<IEnumerable<ITemplate>>(
(templates, enumerable) => templates.UnsortedSequenceEqual(enumerable),
templates => templates.GetHashCode());
/// <inheritdoc />
public override ISimpleContentType ToSimple() => new SimpleContentType(this);

/// <summary>
/// Gets or sets the alias of the default Template.
/// TODO: This should be ignored from cloning!!!!!!!!!!!!!!
/// - but to do that we have to implement callback hacks, this needs to be fixed in v8,
/// Gets or sets the alias of the default Template.
/// TODO: This should be ignored from cloning!!!!!!!!!!!!!!
/// - but to do that we have to implement callback hacks, this needs to be fixed in v8,
/// we should not store direct entity
/// </summary>
[IgnoreDataMember]
public ITemplate DefaultTemplate
{
get { return AllowedTemplates.FirstOrDefault(x => x != null && x.Id == DefaultTemplateId); }
}
public ITemplate DefaultTemplate =>
AllowedTemplates.FirstOrDefault(x => x != null && x.Id == DefaultTemplateId);


[DataMember]
Expand All @@ -74,9 +76,9 @@ public int DefaultTemplateId
}

/// <summary>
/// Gets or Sets a list of Templates which are allowed for the ContentType
/// TODO: This should be ignored from cloning!!!!!!!!!!!!!!
/// - but to do that we have to implement callback hacks, this needs to be fixed in v8,
/// Gets or Sets a list of Templates which are allowed for the ContentType
/// TODO: This should be ignored from cloning!!!!!!!!!!!!!!
/// - but to do that we have to implement callback hacks, this needs to be fixed in v8,
/// we should not store direct entity
/// </summary>
[DataMember]
Expand All @@ -88,38 +90,38 @@ public IEnumerable<ITemplate> AllowedTemplates
SetPropertyValueAndDetectChanges(value, ref _allowedTemplates, nameof(AllowedTemplates), TemplateComparer);

if (_allowedTemplates.Any(x => x.Id == _defaultTemplate) == false)
{
DefaultTemplateId = 0;
}
}
}

public HistoryCleanup HistoryCleanup { get; set; }

/// <summary>
/// Determines if AllowedTemplates contains templateId
/// Determines if AllowedTemplates contains templateId
/// </summary>
/// <param name="templateId">The template id to check</param>
/// <returns>True if AllowedTemplates contains the templateId else False</returns>
public bool IsAllowedTemplate(int templateId)
{
return AllowedTemplates == null
public bool IsAllowedTemplate(int templateId) =>
AllowedTemplates == null
? false
: AllowedTemplates.Any(t => t.Id == templateId);
}

/// <summary>
/// Determines if AllowedTemplates contains templateId
/// Determines if AllowedTemplates contains templateId
/// </summary>
/// <param name="templateAlias">The template alias to check</param>
/// <returns>True if AllowedTemplates contains the templateAlias else False</returns>
public bool IsAllowedTemplate(string templateAlias)
{
return AllowedTemplates == null
public bool IsAllowedTemplate(string templateAlias) =>
AllowedTemplates == null
? false
: AllowedTemplates.Any(t => t.Alias.Equals(templateAlias, StringComparison.InvariantCultureIgnoreCase));
}

/// <summary>
/// Sets the default template for the ContentType
/// Sets the default template for the ContentType
/// </summary>
/// <param name="template">Default <see cref="ITemplate"/></param>
/// <param name="template">Default <see cref="ITemplate" /></param>
public void SetDefaultTemplate(ITemplate template)
{
if (template == null)
Expand All @@ -138,24 +140,27 @@ public void SetDefaultTemplate(ITemplate template)
}

/// <summary>
/// Removes a template from the list of allowed templates
/// Removes a template from the list of allowed templates
/// </summary>
/// <param name="template"><see cref="ITemplate"/> to remove</param>
/// <param name="template"><see cref="ITemplate" /> to remove</param>
/// <returns>True if template was removed, otherwise False</returns>
public bool RemoveTemplate(ITemplate template)
{
if (DefaultTemplateId == template.Id)
DefaultTemplateId = default(int);
{
DefaultTemplateId = default;
}

var templates = AllowedTemplates.ToList();
var remove = templates.FirstOrDefault(x => x.Id == template.Id);
ITemplate remove = templates.FirstOrDefault(x => x.Id == template.Id);
var result = templates.Remove(remove);
AllowedTemplates = templates;

return result;
}

/// <inheritdoc />
IContentType IContentType.DeepCloneWithResetIdentities(string newAlias) => (IContentType)DeepCloneWithResetIdentities(newAlias);
IContentType IContentType.DeepCloneWithResetIdentities(string newAlias) =>
(IContentType)DeepCloneWithResetIdentities(newAlias);
}
}
17 changes: 17 additions & 0 deletions src/Umbraco.Core/Models/ContentVersionCleanupPolicySettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;

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 DateTime Updated { get; set; }
}
}
24 changes: 24 additions & 0 deletions src/Umbraco.Core/Models/HistoricContentVersionMeta.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;

namespace Umbraco.Cms.Core.Models
{
public class HistoricContentVersionMeta
{
public int ContentId { get; }
public int ContentTypeId { get; }
public int VersionId { get; }
public DateTime VersionDate { get; }

public HistoricContentVersionMeta() { }

public HistoricContentVersionMeta(int contentId, int contentTypeId, int versionId, DateTime versionDate)
{
ContentId = contentId;
ContentTypeId = contentTypeId;
VersionId = versionId;
VersionDate = versionDate;
}

public override string ToString() => $"HistoricContentVersionMeta(versionId: {VersionId}, versionDate: {VersionDate:s}";
}
}
Loading

0 comments on commit f694a09

Please sign in to comment.