Skip to content

Commit 7b98cc3

Browse files
authored
Merge pull request #11495 from umbraco/v8/feature/version-history-cleanup
Version history cleanup
2 parents 2ec77a2 + 02dfb5a commit 7b98cc3

File tree

53 files changed

+1939
-352
lines changed

Some content is hidden

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

53 files changed

+1939
-352
lines changed

src/Umbraco.Core/Composing/CompositionExtensions/Repositories.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public static Composition ComposeRepositories(this Composition composition)
4949
composition.RegisterUnique<IContentTypeCommonRepository, ContentTypeCommonRepository>();
5050
composition.RegisterUnique<IInstallationRepository, InstallationRepository>();
5151
composition.RegisterUnique<IUpgradeCheckRepository, UpgradeCheckRepository>();
52+
composition.RegisterUnique<IDocumentVersionRepository, DocumentVersionRepository>();
5253

5354
return composition;
5455
}

src/Umbraco.Core/Composing/CompositionExtensions/Services.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ public static Composition ComposeServices(this Composition composition)
3131
composition.RegisterUnique<IDomainService, DomainService>();
3232
composition.RegisterUnique<IAuditService, AuditService>();
3333
composition.RegisterUnique<ITagService, TagService>();
34-
composition.RegisterUnique<IContentService, ContentService>();
34+
35+
composition.RegisterUnique<ContentService>();
36+
composition.RegisterUnique<IContentService>(factory => factory.GetInstance<ContentService>());
37+
composition.RegisterUnique<IContentVersionService>(factory => factory.GetInstance<ContentService>());
38+
composition.RegisterUnique<IContentVersionCleanupPolicy, DefaultContentVersionCleanupPolicy>();
39+
3540
composition.RegisterUnique<IUserService, UserService>();
3641
composition.RegisterUnique<IMemberService, MemberService>();
3742
composition.RegisterUnique<IMediaService, MediaService>();

src/Umbraco.Core/Configuration/UmbracoSettings/ContentElement.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ internal class ContentElement : UmbracoConfigurationElement, IContentSection
2222
[ConfigurationProperty("notifications", IsRequired = true)]
2323
internal NotificationsElement Notifications => (NotificationsElement) base["notifications"];
2424

25+
[ConfigurationProperty("contentVersionCleanupPolicyGlobalSettings", IsRequired = false)]
26+
internal ContentVersionCleanupPolicyGlobalSettingsElement ContentVersionCleanupPolicyGlobalSettingsElement => (ContentVersionCleanupPolicyGlobalSettingsElement) this["contentVersionCleanupPolicyGlobalSettings"];
27+
2528
[ConfigurationProperty("PreviewBadge")]
2629
internal InnerTextConfigurationElement<string> PreviewBadge => GetOptionalTextElement("PreviewBadge", DefaultPreviewBadge);
2730

@@ -61,6 +64,8 @@ internal class ContentElement : UmbracoConfigurationElement, IContentSection
6164

6265
IEnumerable<string> IContentSection.AllowedUploadFiles => AllowedUploadFiles;
6366

67+
IContentVersionCleanupPolicyGlobalSettings IContentSection.ContentVersionCleanupPolicyGlobalSettings => ContentVersionCleanupPolicyGlobalSettingsElement;
68+
6469
bool IContentSection.ShowDeprecatedPropertyEditors => ShowDeprecatedPropertyEditors;
6570

6671
string IContentSection.LoginBackgroundImage => LoginBackgroundImage;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Configuration;
2+
3+
namespace Umbraco.Core.Configuration.UmbracoSettings
4+
{
5+
internal class ContentVersionCleanupPolicyGlobalSettingsElement : UmbracoConfigurationElement, IContentVersionCleanupPolicyGlobalSettings
6+
{
7+
[ConfigurationProperty("enable", DefaultValue = false)]
8+
public bool EnableCleanup => (bool)this["enable"];
9+
10+
[ConfigurationProperty("keepAllVersionsNewerThanDays", DefaultValue = 2)]
11+
public int KeepAllVersionsNewerThanDays => (int)this["keepAllVersionsNewerThanDays"];
12+
13+
[ConfigurationProperty("keepLatestVersionPerDayForDays", DefaultValue = 30)]
14+
public int KeepLatestVersionPerDayForDays => (int)this["keepLatestVersionPerDayForDays"];
15+
}
16+
}

src/Umbraco.Core/Configuration/UmbracoSettings/IContentSection.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public interface IContentSection : IUmbracoConfigurationSection
2525

2626
IEnumerable<string> AllowedUploadFiles { get; }
2727

28+
IContentVersionCleanupPolicyGlobalSettings ContentVersionCleanupPolicyGlobalSettings { get; }
29+
2830
/// <summary>
2931
/// Gets a value indicating whether to show deprecated property editors in
3032
/// a datatype list of available editors.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Umbraco.Core.Configuration.UmbracoSettings
2+
{
3+
public interface IContentVersionCleanupPolicyGlobalSettings
4+
{
5+
bool EnableCleanup { get; }
6+
int KeepAllVersionsNewerThanDays { get; }
7+
int KeepLatestVersionPerDayForDays { get; }
8+
}
9+
}

src/Umbraco.Core/Migrations/Install/DatabaseSchemaCreator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ public DatabaseSchemaCreator(IUmbracoDatabase database, ILogger logger)
8585
typeof (AuditEntryDto),
8686
typeof (ContentVersionCultureVariationDto),
8787
typeof (DocumentCultureVariationDto),
88-
typeof (ContentScheduleDto)
88+
typeof (ContentScheduleDto),
89+
typeof (ContentVersionCleanupPolicyDto)
8990
};
9091

9192
/// <summary>

src/Umbraco.Core/Migrations/Upgrade/UmbracoPlan.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Umbraco.Core.Migrations.Upgrade.V_8_10_0;
1212
using Umbraco.Core.Migrations.Upgrade.V_8_15_0;
1313
using Umbraco.Core.Migrations.Upgrade.V_8_17_0;
14+
using Umbraco.Core.Migrations.Upgrade.V_8_18_0;
1415

1516
namespace Umbraco.Core.Migrations.Upgrade
1617
{
@@ -211,6 +212,7 @@ protected void DefinePlan()
211212
To<AddPropertyTypeGroupColumns>("{153865E9-7332-4C2A-9F9D-F20AEE078EC7}");
212213

213214
//FINAL
215+
To<AddContentVersionCleanupFeature>("{8BAF5E6C-DCB7-41AE-824F-4215AE4F1F98}");
214216
}
215217
}
216218
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Umbraco.Core.Persistence.Dtos;
2+
3+
namespace Umbraco.Core.Migrations.Upgrade.V_8_18_0
4+
{
5+
class AddContentVersionCleanupFeature : MigrationBase
6+
{
7+
public AddContentVersionCleanupFeature(IMigrationContext context)
8+
: base(context) { }
9+
10+
/// <remarks>
11+
/// The conditionals are useful to enable the same migration to be used in multiple
12+
/// migration paths x.x -> 8.18 and x.x -> 9.x
13+
/// </remarks>
14+
public override void Migrate()
15+
{
16+
var tables = SqlSyntax.GetTablesInSchema(Context.Database);
17+
if (!tables.InvariantContains(ContentVersionCleanupPolicyDto.TableName))
18+
{
19+
Create.Table<ContentVersionCleanupPolicyDto>().Do();
20+
}
21+
22+
var columns = SqlSyntax.GetColumnsInSchema(Context.Database);
23+
AddColumnIfNotExists<ContentVersionDto>(columns, "preventCleanup");
24+
}
25+
}
26+
}
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.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+
}
18+

0 commit comments

Comments
 (0)