mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Changed the term "threshold" to "retention period" for clarity.
This commit is contained in:
@@ -24,12 +24,12 @@ namespace Orchard.AuditTrail.Drivers {
|
||||
|
||||
return ContentShape("Parts_AuditTrailTrimmingSettings_Edit", () => {
|
||||
var viewModel = new AuditTrailTrimmingSettingsViewModel {
|
||||
Threshold = part.Threshold,
|
||||
RetentionPeriod = part.RetentionPeriod,
|
||||
};
|
||||
|
||||
if (updater != null) {
|
||||
if (updater.TryUpdateModel(viewModel, Prefix, null, null)) {
|
||||
part.Threshold = viewModel.Threshold;
|
||||
part.RetentionPeriod = viewModel.RetentionPeriod;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -10,7 +10,7 @@ using Orchard.Localization;
|
||||
namespace Orchard.AuditTrail.Handlers {
|
||||
[OrchardFeature("Orchard.AuditTrail.Trimming")]
|
||||
public class AuditTrailTrimmingSettingsPartHandler : ContentHandler {
|
||||
private int _oldThreshold;
|
||||
private int _oldRetentionPeriod;
|
||||
private readonly IAuditTrailManager _auditTrailManager;
|
||||
private readonly IWorkContextAccessor _wca;
|
||||
|
||||
@@ -31,21 +31,21 @@ namespace Orchard.AuditTrail.Handlers {
|
||||
}
|
||||
|
||||
private void BeginUpdateEvent(UpdateContentContext context, AuditTrailTrimmingSettingsPart part) {
|
||||
_oldThreshold = part.Threshold;
|
||||
_oldRetentionPeriod = part.RetentionPeriod;
|
||||
}
|
||||
|
||||
private void EndUpdateEvent(UpdateContentContext context, AuditTrailTrimmingSettingsPart part) {
|
||||
var newThreshold = part.Threshold;
|
||||
var newRetentionPeriod = part.RetentionPeriod;
|
||||
|
||||
if (newThreshold == _oldThreshold)
|
||||
if (newRetentionPeriod == _oldRetentionPeriod)
|
||||
return;
|
||||
|
||||
_auditTrailManager.CreateRecord<TrimmingSettingsAuditTrailEventProvider>(
|
||||
eventName: TrimmingSettingsAuditTrailEventProvider.TrimmingSettingsChanged,
|
||||
user: _wca.GetContext().CurrentUser,
|
||||
eventData: new Dictionary<string, object> {
|
||||
{"OldThreshold", _oldThreshold},
|
||||
{"NewThreshold", newThreshold}
|
||||
{"OldRetentionPeriod", _oldRetentionPeriod},
|
||||
{"NewRetentionPeriod", newRetentionPeriod}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -4,15 +4,15 @@ using Orchard.ContentManagement;
|
||||
namespace Orchard.AuditTrail.Models {
|
||||
public class AuditTrailTrimmingSettingsPart : ContentPart {
|
||||
/// <summary>
|
||||
/// Threshold in days.
|
||||
/// Gets or sets the retention period in days of audit trail records before they are deleted.
|
||||
/// </summary>
|
||||
public int Threshold {
|
||||
get { return this.Retrieve(x => x.Threshold, defaultValue: 10); }
|
||||
set { this.Store(x => x.Threshold, value); }
|
||||
public int RetentionPeriod {
|
||||
get { return this.Retrieve(x => x.RetentionPeriod, defaultValue: 10); }
|
||||
set { this.Store(x => x.RetentionPeriod, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The timestamp the audit trail was last trimmed.
|
||||
/// Gets or sets the time in UTC at which the audit trail was last trimmed.
|
||||
/// </summary>
|
||||
public DateTime? LastRunUtc {
|
||||
get { return this.Retrieve(x => x.LastRunUtc); }
|
||||
|
@@ -202,8 +202,8 @@ namespace Orchard.AuditTrail.Services {
|
||||
return eventDescriptors.First();
|
||||
}
|
||||
|
||||
public IEnumerable<AuditTrailEventRecord> Trim(TimeSpan threshold) {
|
||||
var dateThreshold = _clock.UtcNow.Date - threshold;
|
||||
public IEnumerable<AuditTrailEventRecord> Trim(TimeSpan retentionPeriod) {
|
||||
var dateThreshold = _clock.UtcNow.Date - retentionPeriod;
|
||||
var query = _auditTrailRepository.Table.Where(x => x.CreatedUtc < dateThreshold);
|
||||
var records = query.ToArray();
|
||||
|
||||
|
@@ -37,7 +37,7 @@ namespace Orchard.AuditTrail.Services {
|
||||
return;
|
||||
|
||||
Logger.Debug("Starting audit trail trimming operation.");
|
||||
var deletedRecords = _auditTrailManager.Trim(TimeSpan.FromDays(Settings.Threshold));
|
||||
var deletedRecords = _auditTrailManager.Trim(TimeSpan.FromDays(Settings.RetentionPeriod));
|
||||
Logger.Debug("Audit trail trimming operation completed. {0} records were deleted.", deletedRecords.Count());
|
||||
Settings.LastRunUtc = _clock.UtcNow;
|
||||
}
|
||||
|
@@ -8,27 +8,27 @@ using Orchard.Security;
|
||||
namespace Orchard.AuditTrail.Services {
|
||||
public interface IAuditTrailManager : IDependency {
|
||||
/// <summary>
|
||||
/// Gets a page of event records.
|
||||
/// Returns a page of event records.
|
||||
/// </summary>
|
||||
/// <param name="page">The page number to get records from.</param>
|
||||
/// <param name="pageSize">The number of records to get.</param>
|
||||
/// <param name="orderBy">The value to order by.</param>
|
||||
/// <param name="filters">Optional. An object to filter the records on.</param>
|
||||
/// <returns>Returns a page of event records.</returns>
|
||||
/// <returns>A page of event records.</returns>
|
||||
IPageOfItems<AuditTrailEventRecord> GetRecords(int page, int pageSize, Filters filters = null, AuditTrailOrderBy orderBy = AuditTrailOrderBy.DateDescending);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a single event record by ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The event record ID.</param>
|
||||
/// <returns>Returns a single event record by ID.</returns>
|
||||
/// <returns>A single event record by ID.</returns>
|
||||
AuditTrailEventRecord GetRecord(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Builds a shape tree of filter displays.
|
||||
/// </summary>
|
||||
/// <param name="filters">Input for each filter builder.</param>
|
||||
/// <returns>Returns a tree of shapes.</returns>
|
||||
/// <returns>A tree of shapes.</returns>
|
||||
dynamic BuildFilterDisplays(Filters filters);
|
||||
|
||||
/// <summary>
|
||||
@@ -41,13 +41,13 @@ namespace Orchard.AuditTrail.Services {
|
||||
/// <param name="eventData">A property bag of custom event data that will be stored with the event record.</param>
|
||||
/// <param name="eventFilterKey">The name of a custom key to use when filtering events.</param>
|
||||
/// <param name="eventFilterData">The value of a custom filter key to filter on.</param>
|
||||
/// <returns>Returns the created audit trail event record if the specified event was not disabled.</returns>
|
||||
/// <returns>The created audit trail event record if the specified event was not disabled.</returns>
|
||||
AuditTrailEventRecordResult CreateRecord<T>(string eventName, IUser user, IDictionary<string, object> properties = null, IDictionary<string, object> eventData = null, string eventFilterKey = null, string eventFilterData = null) where T : IAuditTrailEventProvider;
|
||||
|
||||
/// <summary>
|
||||
/// Describes all audit trail events provided by the system.
|
||||
/// </summary>
|
||||
/// <returns>Returns a list of audit trail category descriptors.</returns>
|
||||
/// <returns>A list of audit trail category descriptors.</returns>
|
||||
IEnumerable<AuditTrailCategoryDescriptor> DescribeCategories();
|
||||
|
||||
/// <summary>
|
||||
@@ -60,21 +60,21 @@ namespace Orchard.AuditTrail.Services {
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The scope of the specified event name.</typeparam>
|
||||
/// <param name="eventName">The shorthand name of the event.</param>
|
||||
/// <returns>Returns a single audit trail event descriptor.</returns>
|
||||
/// <returns>A single audit trail event descriptor.</returns>
|
||||
AuditTrailEventDescriptor DescribeEvent<T>(string eventName) where T : IAuditTrailEventProvider;
|
||||
|
||||
/// <summary>
|
||||
/// Describes a single audit trail event.
|
||||
/// </summary>
|
||||
/// <param name="fullyQualifiedEventName">The fully qualified event name to describe.</param>
|
||||
/// <returns>Returns a single audit trail event descriptor.</returns>
|
||||
/// <returns>A single audit trail event descriptor.</returns>
|
||||
AuditTrailEventDescriptor DescribeEvent(string fullyQualifiedEventName);
|
||||
|
||||
/// <summary>
|
||||
/// Trims the audit trail by deleting all records older than the specified threshold.
|
||||
/// Trims the audit trail by deleting all records older than the specified retention period.
|
||||
/// </summary>
|
||||
/// <returns>Returns the deleted records.</returns>
|
||||
IEnumerable<AuditTrailEventRecord> Trim(TimeSpan threshold);
|
||||
/// <returns>A list of deleted records.</returns>
|
||||
IEnumerable<AuditTrailEventRecord> Trim(TimeSpan retentionPeriod);
|
||||
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
namespace Orchard.AuditTrail.ViewModels {
|
||||
public class AuditTrailTrimmingSettingsViewModel {
|
||||
public int Threshold { get; set; }
|
||||
public int RetentionPeriod { get; set; }
|
||||
}
|
||||
}
|
@@ -1,10 +1,10 @@
|
||||
@using Orchard.AuditTrail.Helpers
|
||||
@{
|
||||
var eventData = (IDictionary<string, object>)Model.EventData;
|
||||
var oldThreshold = eventData.Get<int>("OldThreshold");
|
||||
var newThreshold = eventData.Get<int>("NewThreshold");
|
||||
var oldRetentionPeriod = eventData.Get<int>("OldRetentionPeriod");
|
||||
var newRetentionPeriod = eventData.Get<int>("NewRetentionPeriod");
|
||||
}
|
||||
|
||||
<fieldset>
|
||||
@T("Trimming threshold changed from <strong>{0}</strong> to <strong>{1}</strong>", oldThreshold, newThreshold)
|
||||
@T("Trimming retention period changed from <strong>{0}</strong> to <strong>{1}</strong>", oldRetentionPeriod, newRetentionPeriod)
|
||||
</fieldset>
|
@@ -1,9 +1,9 @@
|
||||
@model Orchard.AuditTrail.ViewModels.AuditTrailTrimmingSettingsViewModel
|
||||
<fieldset>
|
||||
<legend>@T("Auto Trim Settings")</legend>
|
||||
<div id="auditTrailAutoTrimthresholdSetting">
|
||||
@Html.LabelFor(m => m.Threshold, T("Auto-trim threshold"))
|
||||
@Html.TextBoxFor(m => m.Threshold, new { @class = "text small" })
|
||||
<span class="hint">@T("Specify the number of days of audit log data to retain.")</span>
|
||||
<legend>@T("Trimming Settings")</legend>
|
||||
<div id="audittrail-trimming-retentionperiod-setting">
|
||||
@Html.LabelFor(m => m.RetentionPeriod, T("Retention period"))
|
||||
@Html.TextBoxFor(m => m.RetentionPeriod, new { @class = "text small" })
|
||||
<span class="hint">@T("The number of days of audit log data to retain.")</span>
|
||||
</div>
|
||||
</fieldset>
|
Reference in New Issue
Block a user