mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Fixed localization of last trimming run date display. Added range validation to trimming settings. Added configurable setting for minimum trimming run interval.
This commit is contained in:
@@ -3,6 +3,7 @@ using Orchard.AuditTrail.ViewModels;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Localization.Services;
|
||||
using Orchard.Security;
|
||||
|
||||
@@ -11,12 +12,17 @@ namespace Orchard.AuditTrail.Drivers {
|
||||
public class AuditTrailTrimmingSettingsPartDriver : ContentPartDriver<AuditTrailTrimmingSettingsPart> {
|
||||
private readonly IAuthorizer _authorizer;
|
||||
private readonly IDateServices _dateServices;
|
||||
private readonly IDateTimeFormatProvider _dateTimeLocalization;
|
||||
|
||||
public AuditTrailTrimmingSettingsPartDriver(IAuthorizer authorizer, IDateServices dateServices) {
|
||||
public AuditTrailTrimmingSettingsPartDriver(IAuthorizer authorizer, IDateServices dateServices, IDateTimeFormatProvider dateTimeLocalization) {
|
||||
_authorizer = authorizer;
|
||||
_dateServices = dateServices;
|
||||
_dateTimeLocalization = dateTimeLocalization;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
protected override DriverResult Editor(AuditTrailTrimmingSettingsPart part, dynamic shapeHelper) {
|
||||
return Editor(part, null, shapeHelper);
|
||||
}
|
||||
@@ -28,7 +34,8 @@ namespace Orchard.AuditTrail.Drivers {
|
||||
return ContentShape("Parts_AuditTrailTrimmingSettings_Edit", () => {
|
||||
var viewModel = new AuditTrailTrimmingSettingsViewModel {
|
||||
RetentionPeriod = part.RetentionPeriod,
|
||||
LastRun = _dateServices.ConvertToLocal(part.LastRunUtc)
|
||||
MinimumRunInterval = part.MinimumRunInterval,
|
||||
LastRunDateString = _dateServices.ConvertToLocalString(part.LastRunUtc, _dateTimeLocalization.ShortDateTimeFormat, T("Never").Text)
|
||||
};
|
||||
|
||||
if (updater != null) {
|
||||
|
@@ -11,6 +11,14 @@ namespace Orchard.AuditTrail.Models {
|
||||
set { this.Store(x => x.RetentionPeriod, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the miminum wait time in hours between audit trail trimming runs.
|
||||
/// </summary>
|
||||
public int MinimumRunInterval {
|
||||
get { return this.Retrieve(x => x.MinimumRunInterval, defaultValue: 12); }
|
||||
set { this.Store(x => x.MinimumRunInterval, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the time in UTC at which the audit trail was last trimmed.
|
||||
/// </summary>
|
||||
|
@@ -66,8 +66,8 @@ namespace Orchard.AuditTrail.Services {
|
||||
private bool GetIsTimeToTrim() {
|
||||
var lastRun = Settings.LastRunUtc ?? DateTime.MinValue;
|
||||
var now = _clock.UtcNow;
|
||||
var interval = TimeSpan.FromHours(12);
|
||||
return now - lastRun > interval;
|
||||
var interval = TimeSpan.FromHours(Settings.MinimumRunInterval);
|
||||
return now - lastRun >= interval;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Orchard.AuditTrail.ViewModels {
|
||||
public class AuditTrailTrimmingSettingsViewModel {
|
||||
public int RetentionPeriod { get; set; }
|
||||
public DateTime? LastRun { get; set; }
|
||||
[Range(0, Int32.MaxValue)] public int RetentionPeriod { get; set; }
|
||||
[Range(0, Int32.MaxValue)] public int MinimumRunInterval { get; set; }
|
||||
public string LastRunDateString { get; set; }
|
||||
}
|
||||
}
|
@@ -7,8 +7,13 @@
|
||||
<span class="hint">@T("The number of days of audit log data to retain.")</span>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
@Html.LabelFor(m => m.LastRun, T("Last run"))
|
||||
@Html.TextBoxFor(m => m.LastRun, new { @class = "text", disabled = "disabled" })
|
||||
<span class="hint">@T("Indicates the last time the audit trail trimming process was run. The trimming process runs every 12 hours.")</span>
|
||||
@Html.LabelFor(m => m.MinimumRunInterval, T("Minimum run interval"))
|
||||
@Html.TextBoxFor(m => m.MinimumRunInterval, new { @class = "text small" })
|
||||
<span class="hint">@T("The minimum number of hours to wait between trimming process runs. Enter 0 for continuous trimming.")</span>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
@Html.LabelFor(m => m.LastRunDateString, T("Last run"))
|
||||
@Html.TextBoxFor(m => m.LastRunDateString, new { @class = "text", disabled = "disabled" })
|
||||
<span class="hint">@T("Indicates the last time the audit trail trimming process was run.")</span>
|
||||
</fieldset>
|
||||
</section>
|
||||
|
Reference in New Issue
Block a user