Skip to content

Commit f694a09

Browse files
authored
Merge pull request #11562 from umbraco/v9/feature/merge_and_clean_history_cleanup
V9: Merged History cleanup from v8 and refactored to v9
2 parents ef4a0f8 + 53a83ab commit f694a09

File tree

50 files changed

+5805
-1060
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+5805
-1060
lines changed

build/templates/UmbracoProject/appsettings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
//#endif
3030
"Hosting": {
3131
"Debug": false
32+
},
33+
"Content": {
34+
"ContentVersionCleanupPolicy": {
35+
"EnableCleanup": true
36+
}
3237
}
3338
}
3439
}

src/Umbraco.Core/Configuration/Models/ContentSettings.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ @keyframes umbraco-preview-badge--effect {{
219219
[DefaultValue(StaticLoginLogoImage)]
220220
public string LoginLogoImage { get; set; } = StaticLoginLogoImage;
221221

222-
222+
/// <summary>
223+
/// Get or sets the model representing the global content version cleanup policy
224+
/// </summary>
225+
public ContentVersionCleanupPolicySettings ContentVersionCleanupPolicy { get; set; } = new ContentVersionCleanupPolicySettings();
223226
}
224227
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.ComponentModel;
2+
3+
namespace Umbraco.Cms.Core.Configuration.Models
4+
{
5+
/// <summary>
6+
/// Model representing the global content version cleanup policy
7+
/// </summary>
8+
public class ContentVersionCleanupPolicySettings
9+
{
10+
private const bool StaticEnableCleanup = false;
11+
private const int StaticKeepAllVersionsNewerThanDays = 7;
12+
private const int StaticKeepLatestVersionPerDayForDays = 90;
13+
14+
/// <summary>
15+
/// Gets or sets a value indicating whether or not the cleanup job should be executed.
16+
/// </summary>
17+
[DefaultValue(StaticEnableCleanup)]
18+
public bool EnableCleanup { get; set; } = StaticEnableCleanup;
19+
20+
/// <summary>
21+
/// Gets or sets the number of days where all historical content versions are kept.
22+
/// </summary>
23+
[DefaultValue(StaticKeepAllVersionsNewerThanDays)]
24+
public int KeepAllVersionsNewerThanDays { get; set; } = StaticKeepAllVersionsNewerThanDays;
25+
26+
/// <summary>
27+
/// Gets or sets the number of days where the latest historical content version for that day are kept.
28+
/// </summary>
29+
[DefaultValue(StaticKeepLatestVersionPerDayForDays)]
30+
public int KeepLatestVersionPerDayForDays { get; set; } = StaticKeepLatestVersionPerDayForDays;
31+
32+
}
33+
}

src/Umbraco.Core/Models/ContentEditing/ContentTypeSave.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ protected ContentTypeSave()
2929
[DataMember(Name = "allowedContentTypes")]
3030
public IEnumerable<int> AllowedContentTypes { get; set; }
3131

32+
[DataMember(Name = "historyCleanup")]
33+
public HistoryCleanupViewModel HistoryCleanup { get; set; }
34+
3235
/// <summary>
3336
/// Custom validation
3437
/// </summary>

src/Umbraco.Core/Models/ContentEditing/DocumentTypeDisplay.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Generic;
22
using System.Runtime.Serialization;
33

44
namespace Umbraco.Cms.Core.Models.ContentEditing
55
{
66
[DataContract(Name = "contentType", Namespace = "")]
77
public class DocumentTypeDisplay : ContentTypeCompositionDisplay<PropertyTypeDisplay>
88
{
9-
public DocumentTypeDisplay()
10-
{
9+
public DocumentTypeDisplay() =>
1110
//initialize collections so at least their never null
1211
AllowedTemplates = new List<EntityBasic>();
13-
}
1412

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

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

3028
[DataMember(Name = "apps")]
3129
public IEnumerable<ContentApp> ContentApps { get; set; }
30+
31+
[DataMember(Name = "historyCleanup")]
32+
public HistoryCleanupViewModel HistoryCleanup { get; set; }
3233
}
3334
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace Umbraco.Cms.Core.Models.ContentEditing
4+
{
5+
[DataContract(Name = "historyCleanup", Namespace = "")]
6+
public class HistoryCleanup
7+
{
8+
[DataMember(Name = "preventCleanup")]
9+
public bool PreventCleanup { get; set; }
10+
11+
[DataMember(Name = "keepAllVersionsNewerThanDays")]
12+
public int? KeepAllVersionsNewerThanDays { get; set; }
13+
14+
[DataMember(Name = "keepLatestVersionPerDayForDays")]
15+
public int? KeepLatestVersionPerDayForDays { get; set; }
16+
}
17+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace Umbraco.Cms.Core.Models.ContentEditing
4+
{
5+
[DataContract(Name = "historyCleanup", Namespace = "")]
6+
public class HistoryCleanupViewModel : HistoryCleanup
7+
{
8+
9+
[DataMember(Name = "globalEnableCleanup")]
10+
public bool GlobalEnableCleanup { get; set; }
11+
12+
[DataMember(Name = "globalKeepAllVersionsNewerThanDays")]
13+
public int? GlobalKeepAllVersionsNewerThanDays { get; set; }
14+
15+
[DataMember(Name = "globalKeepLatestVersionPerDayForDays")]
16+
public int? GlobalKeepLatestVersionPerDayForDays { get; set; }
17+
}
18+
}
Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,45 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Runtime.Serialization;
5+
using Umbraco.Cms.Core.Models.ContentEditing;
56
using Umbraco.Cms.Core.Strings;
67
using Umbraco.Extensions;
78

89
namespace Umbraco.Cms.Core.Models
910
{
1011
/// <summary>
11-
/// Represents the content type that a <see cref="Content"/> object is based on
12+
/// Represents the content type that a <see cref="Content" /> object is based on
1213
/// </summary>
1314
[Serializable]
1415
[DataContract(IsReference = true)]
15-
public class ContentType : ContentTypeCompositionBase, IContentType
16+
public class ContentType : ContentTypeCompositionBase, IContentTypeWithHistoryCleanup
1617
{
1718
public const bool SupportsPublishingConst = true;
1819

19-
private int _defaultTemplate;
20+
// Custom comparer for enumerable
21+
private static readonly DelegateEqualityComparer<IEnumerable<ITemplate>> TemplateComparer = new (
22+
(templates, enumerable) => templates.UnsortedSequenceEqual(enumerable),
23+
templates => templates.GetHashCode());
24+
2025
private IEnumerable<ITemplate> _allowedTemplates;
2126

27+
private int _defaultTemplate;
28+
2229
/// <summary>
23-
/// Constuctor for creating a ContentType with the parent's id.
30+
/// Constuctor for creating a ContentType with the parent's id.
2431
/// </summary>
2532
/// <remarks>Only use this for creating ContentTypes at the root (with ParentId -1).</remarks>
2633
/// <param name="parentId"></param>
2734
public ContentType(IShortStringHelper shortStringHelper, int parentId) : base(shortStringHelper, parentId)
2835
{
2936
_allowedTemplates = new List<ITemplate>();
37+
HistoryCleanup = new HistoryCleanup();
3038
}
3139

3240

3341
/// <summary>
34-
/// Constuctor for creating a ContentType with the parent as an inherited type.
42+
/// Constuctor for creating a ContentType with the parent as an inherited type.
3543
/// </summary>
3644
/// <remarks>Use this to ensure inheritance from parent.</remarks>
3745
/// <param name="parent"></param>
@@ -40,30 +48,24 @@ public ContentType(IShortStringHelper shortStringHelper, IContentType parent, st
4048
: base(shortStringHelper, parent, alias)
4149
{
4250
_allowedTemplates = new List<ITemplate>();
51+
HistoryCleanup = new HistoryCleanup();
4352
}
4453

45-
/// <inheritdoc />
46-
public override ISimpleContentType ToSimple() => new SimpleContentType(this);
47-
4854
/// <inheritdoc />
4955
public override bool SupportsPublishing => SupportsPublishingConst;
5056

51-
//Custom comparer for enumerable
52-
private static readonly DelegateEqualityComparer<IEnumerable<ITemplate>> TemplateComparer = new DelegateEqualityComparer<IEnumerable<ITemplate>>(
53-
(templates, enumerable) => templates.UnsortedSequenceEqual(enumerable),
54-
templates => templates.GetHashCode());
57+
/// <inheritdoc />
58+
public override ISimpleContentType ToSimple() => new SimpleContentType(this);
5559

5660
/// <summary>
57-
/// Gets or sets the alias of the default Template.
58-
/// TODO: This should be ignored from cloning!!!!!!!!!!!!!!
59-
/// - but to do that we have to implement callback hacks, this needs to be fixed in v8,
61+
/// Gets or sets the alias of the default Template.
62+
/// TODO: This should be ignored from cloning!!!!!!!!!!!!!!
63+
/// - but to do that we have to implement callback hacks, this needs to be fixed in v8,
6064
/// we should not store direct entity
6165
/// </summary>
6266
[IgnoreDataMember]
63-
public ITemplate DefaultTemplate
64-
{
65-
get { return AllowedTemplates.FirstOrDefault(x => x != null && x.Id == DefaultTemplateId); }
66-
}
67+
public ITemplate DefaultTemplate =>
68+
AllowedTemplates.FirstOrDefault(x => x != null && x.Id == DefaultTemplateId);
6769

6870

6971
[DataMember]
@@ -74,9 +76,9 @@ public int DefaultTemplateId
7476
}
7577

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

9092
if (_allowedTemplates.Any(x => x.Id == _defaultTemplate) == false)
93+
{
9194
DefaultTemplateId = 0;
95+
}
9296
}
9397
}
9498

99+
public HistoryCleanup HistoryCleanup { get; set; }
100+
95101
/// <summary>
96-
/// Determines if AllowedTemplates contains templateId
102+
/// Determines if AllowedTemplates contains templateId
97103
/// </summary>
98104
/// <param name="templateId">The template id to check</param>
99105
/// <returns>True if AllowedTemplates contains the templateId else False</returns>
100-
public bool IsAllowedTemplate(int templateId)
101-
{
102-
return AllowedTemplates == null
106+
public bool IsAllowedTemplate(int templateId) =>
107+
AllowedTemplates == null
103108
? false
104109
: AllowedTemplates.Any(t => t.Id == templateId);
105-
}
106110

107111
/// <summary>
108-
/// Determines if AllowedTemplates contains templateId
112+
/// Determines if AllowedTemplates contains templateId
109113
/// </summary>
110114
/// <param name="templateAlias">The template alias to check</param>
111115
/// <returns>True if AllowedTemplates contains the templateAlias else False</returns>
112-
public bool IsAllowedTemplate(string templateAlias)
113-
{
114-
return AllowedTemplates == null
116+
public bool IsAllowedTemplate(string templateAlias) =>
117+
AllowedTemplates == null
115118
? false
116119
: AllowedTemplates.Any(t => t.Alias.Equals(templateAlias, StringComparison.InvariantCultureIgnoreCase));
117-
}
118120

119121
/// <summary>
120-
/// Sets the default template for the ContentType
122+
/// Sets the default template for the ContentType
121123
/// </summary>
122-
/// <param name="template">Default <see cref="ITemplate"/></param>
124+
/// <param name="template">Default <see cref="ITemplate" /></param>
123125
public void SetDefaultTemplate(ITemplate template)
124126
{
125127
if (template == null)
@@ -138,24 +140,27 @@ public void SetDefaultTemplate(ITemplate template)
138140
}
139141

140142
/// <summary>
141-
/// Removes a template from the list of allowed templates
143+
/// Removes a template from the list of allowed templates
142144
/// </summary>
143-
/// <param name="template"><see cref="ITemplate"/> to remove</param>
145+
/// <param name="template"><see cref="ITemplate" /> to remove</param>
144146
/// <returns>True if template was removed, otherwise False</returns>
145147
public bool RemoveTemplate(ITemplate template)
146148
{
147149
if (DefaultTemplateId == template.Id)
148-
DefaultTemplateId = default(int);
150+
{
151+
DefaultTemplateId = default;
152+
}
149153

150154
var templates = AllowedTemplates.ToList();
151-
var remove = templates.FirstOrDefault(x => x.Id == template.Id);
155+
ITemplate remove = templates.FirstOrDefault(x => x.Id == template.Id);
152156
var result = templates.Remove(remove);
153157
AllowedTemplates = templates;
154158

155159
return result;
156160
}
157161

158162
/// <inheritdoc />
159-
IContentType IContentType.DeepCloneWithResetIdentities(string newAlias) => (IContentType)DeepCloneWithResetIdentities(newAlias);
163+
IContentType IContentType.DeepCloneWithResetIdentities(string newAlias) =>
164+
(IContentType)DeepCloneWithResetIdentities(newAlias);
160165
}
161166
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
3+
namespace Umbraco.Cms.Core.Models
4+
{
5+
public class ContentVersionCleanupPolicySettings
6+
{
7+
public int ContentTypeId { get; set; }
8+
9+
public bool PreventCleanup { get; set; }
10+
11+
public int? KeepAllVersionsNewerThanDays { get; set; }
12+
13+
public int? KeepLatestVersionPerDayForDays { get; set; }
14+
15+
public DateTime Updated { get; set; }
16+
}
17+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
3+
namespace Umbraco.Cms.Core.Models
4+
{
5+
public class HistoricContentVersionMeta
6+
{
7+
public int ContentId { get; }
8+
public int ContentTypeId { get; }
9+
public int VersionId { get; }
10+
public DateTime VersionDate { get; }
11+
12+
public HistoricContentVersionMeta() { }
13+
14+
public HistoricContentVersionMeta(int contentId, int contentTypeId, int versionId, DateTime versionDate)
15+
{
16+
ContentId = contentId;
17+
ContentTypeId = contentTypeId;
18+
VersionId = versionId;
19+
VersionDate = versionDate;
20+
}
21+
22+
public override string ToString() => $"HistoricContentVersionMeta(versionId: {VersionId}, versionDate: {VersionDate:s}";
23+
}
24+
}

0 commit comments

Comments
 (0)