Changed the term "threshold" to "retention period" for clarity.

This commit is contained in:
Daniel Stolt
2014-07-05 12:40:12 +02:00
parent eb32aab073
commit 660ab8322e
9 changed files with 36 additions and 36 deletions

View File

@@ -24,12 +24,12 @@ namespace Orchard.AuditTrail.Drivers {
return ContentShape("Parts_AuditTrailTrimmingSettings_Edit", () => { return ContentShape("Parts_AuditTrailTrimmingSettings_Edit", () => {
var viewModel = new AuditTrailTrimmingSettingsViewModel { var viewModel = new AuditTrailTrimmingSettingsViewModel {
Threshold = part.Threshold, RetentionPeriod = part.RetentionPeriod,
}; };
if (updater != null) { if (updater != null) {
if (updater.TryUpdateModel(viewModel, Prefix, null, null)) { if (updater.TryUpdateModel(viewModel, Prefix, null, null)) {
part.Threshold = viewModel.Threshold; part.RetentionPeriod = viewModel.RetentionPeriod;
} }
} }

View File

@@ -10,7 +10,7 @@ using Orchard.Localization;
namespace Orchard.AuditTrail.Handlers { namespace Orchard.AuditTrail.Handlers {
[OrchardFeature("Orchard.AuditTrail.Trimming")] [OrchardFeature("Orchard.AuditTrail.Trimming")]
public class AuditTrailTrimmingSettingsPartHandler : ContentHandler { public class AuditTrailTrimmingSettingsPartHandler : ContentHandler {
private int _oldThreshold; private int _oldRetentionPeriod;
private readonly IAuditTrailManager _auditTrailManager; private readonly IAuditTrailManager _auditTrailManager;
private readonly IWorkContextAccessor _wca; private readonly IWorkContextAccessor _wca;
@@ -31,21 +31,21 @@ namespace Orchard.AuditTrail.Handlers {
} }
private void BeginUpdateEvent(UpdateContentContext context, AuditTrailTrimmingSettingsPart part) { private void BeginUpdateEvent(UpdateContentContext context, AuditTrailTrimmingSettingsPart part) {
_oldThreshold = part.Threshold; _oldRetentionPeriod = part.RetentionPeriod;
} }
private void EndUpdateEvent(UpdateContentContext context, AuditTrailTrimmingSettingsPart part) { private void EndUpdateEvent(UpdateContentContext context, AuditTrailTrimmingSettingsPart part) {
var newThreshold = part.Threshold; var newRetentionPeriod = part.RetentionPeriod;
if (newThreshold == _oldThreshold) if (newRetentionPeriod == _oldRetentionPeriod)
return; return;
_auditTrailManager.CreateRecord<TrimmingSettingsAuditTrailEventProvider>( _auditTrailManager.CreateRecord<TrimmingSettingsAuditTrailEventProvider>(
eventName: TrimmingSettingsAuditTrailEventProvider.TrimmingSettingsChanged, eventName: TrimmingSettingsAuditTrailEventProvider.TrimmingSettingsChanged,
user: _wca.GetContext().CurrentUser, user: _wca.GetContext().CurrentUser,
eventData: new Dictionary<string, object> { eventData: new Dictionary<string, object> {
{"OldThreshold", _oldThreshold}, {"OldRetentionPeriod", _oldRetentionPeriod},
{"NewThreshold", newThreshold} {"NewRetentionPeriod", newRetentionPeriod}
}); });
} }
} }

View File

@@ -4,15 +4,15 @@ using Orchard.ContentManagement;
namespace Orchard.AuditTrail.Models { namespace Orchard.AuditTrail.Models {
public class AuditTrailTrimmingSettingsPart : ContentPart { public class AuditTrailTrimmingSettingsPart : ContentPart {
/// <summary> /// <summary>
/// Threshold in days. /// Gets or sets the retention period in days of audit trail records before they are deleted.
/// </summary> /// </summary>
public int Threshold { public int RetentionPeriod {
get { return this.Retrieve(x => x.Threshold, defaultValue: 10); } get { return this.Retrieve(x => x.RetentionPeriod, defaultValue: 10); }
set { this.Store(x => x.Threshold, value); } set { this.Store(x => x.RetentionPeriod, value); }
} }
/// <summary> /// <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> /// </summary>
public DateTime? LastRunUtc { public DateTime? LastRunUtc {
get { return this.Retrieve(x => x.LastRunUtc); } get { return this.Retrieve(x => x.LastRunUtc); }

View File

@@ -202,8 +202,8 @@ namespace Orchard.AuditTrail.Services {
return eventDescriptors.First(); return eventDescriptors.First();
} }
public IEnumerable<AuditTrailEventRecord> Trim(TimeSpan threshold) { public IEnumerable<AuditTrailEventRecord> Trim(TimeSpan retentionPeriod) {
var dateThreshold = _clock.UtcNow.Date - threshold; var dateThreshold = _clock.UtcNow.Date - retentionPeriod;
var query = _auditTrailRepository.Table.Where(x => x.CreatedUtc < dateThreshold); var query = _auditTrailRepository.Table.Where(x => x.CreatedUtc < dateThreshold);
var records = query.ToArray(); var records = query.ToArray();

View File

@@ -37,7 +37,7 @@ namespace Orchard.AuditTrail.Services {
return; return;
Logger.Debug("Starting audit trail trimming operation."); 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()); Logger.Debug("Audit trail trimming operation completed. {0} records were deleted.", deletedRecords.Count());
Settings.LastRunUtc = _clock.UtcNow; Settings.LastRunUtc = _clock.UtcNow;
} }

View File

@@ -8,27 +8,27 @@ using Orchard.Security;
namespace Orchard.AuditTrail.Services { namespace Orchard.AuditTrail.Services {
public interface IAuditTrailManager : IDependency { public interface IAuditTrailManager : IDependency {
/// <summary> /// <summary>
/// Gets a page of event records. /// Returns a page of event records.
/// </summary> /// </summary>
/// <param name="page">The page number to get records from.</param> /// <param name="page">The page number to get records from.</param>
/// <param name="pageSize">The number of records to get.</param> /// <param name="pageSize">The number of records to get.</param>
/// <param name="orderBy">The value to order by.</param> /// <param name="orderBy">The value to order by.</param>
/// <param name="filters">Optional. An object to filter the records on.</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); IPageOfItems<AuditTrailEventRecord> GetRecords(int page, int pageSize, Filters filters = null, AuditTrailOrderBy orderBy = AuditTrailOrderBy.DateDescending);
/// <summary> /// <summary>
/// Returns a single event record by ID. /// Returns a single event record by ID.
/// </summary> /// </summary>
/// <param name="id">The event record ID.</param> /// <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); AuditTrailEventRecord GetRecord(int id);
/// <summary> /// <summary>
/// Builds a shape tree of filter displays. /// Builds a shape tree of filter displays.
/// </summary> /// </summary>
/// <param name="filters">Input for each filter builder.</param> /// <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); dynamic BuildFilterDisplays(Filters filters);
/// <summary> /// <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="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="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> /// <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; 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> /// <summary>
/// Describes all audit trail events provided by the system. /// Describes all audit trail events provided by the system.
/// </summary> /// </summary>
/// <returns>Returns a list of audit trail category descriptors.</returns> /// <returns>A list of audit trail category descriptors.</returns>
IEnumerable<AuditTrailCategoryDescriptor> DescribeCategories(); IEnumerable<AuditTrailCategoryDescriptor> DescribeCategories();
/// <summary> /// <summary>
@@ -60,21 +60,21 @@ namespace Orchard.AuditTrail.Services {
/// </summary> /// </summary>
/// <typeparam name="T">The scope of the specified event name.</typeparam> /// <typeparam name="T">The scope of the specified event name.</typeparam>
/// <param name="eventName">The shorthand name of the event.</param> /// <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; AuditTrailEventDescriptor DescribeEvent<T>(string eventName) where T : IAuditTrailEventProvider;
/// <summary> /// <summary>
/// Describes a single audit trail event. /// Describes a single audit trail event.
/// </summary> /// </summary>
/// <param name="fullyQualifiedEventName">The fully qualified event name to describe.</param> /// <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); AuditTrailEventDescriptor DescribeEvent(string fullyQualifiedEventName);
/// <summary> /// <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> /// </summary>
/// <returns>Returns the deleted records.</returns> /// <returns>A list of deleted records.</returns>
IEnumerable<AuditTrailEventRecord> Trim(TimeSpan threshold); IEnumerable<AuditTrailEventRecord> Trim(TimeSpan retentionPeriod);
} }
} }

View File

@@ -1,5 +1,5 @@
namespace Orchard.AuditTrail.ViewModels { namespace Orchard.AuditTrail.ViewModels {
public class AuditTrailTrimmingSettingsViewModel { public class AuditTrailTrimmingSettingsViewModel {
public int Threshold { get; set; } public int RetentionPeriod { get; set; }
} }
} }

View File

@@ -1,10 +1,10 @@
@using Orchard.AuditTrail.Helpers @using Orchard.AuditTrail.Helpers
@{ @{
var eventData = (IDictionary<string, object>)Model.EventData; var eventData = (IDictionary<string, object>)Model.EventData;
var oldThreshold = eventData.Get<int>("OldThreshold"); var oldRetentionPeriod = eventData.Get<int>("OldRetentionPeriod");
var newThreshold = eventData.Get<int>("NewThreshold"); var newRetentionPeriod = eventData.Get<int>("NewRetentionPeriod");
} }
<fieldset> <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> </fieldset>

View File

@@ -1,9 +1,9 @@
@model Orchard.AuditTrail.ViewModels.AuditTrailTrimmingSettingsViewModel @model Orchard.AuditTrail.ViewModels.AuditTrailTrimmingSettingsViewModel
<fieldset> <fieldset>
<legend>@T("Auto Trim Settings")</legend> <legend>@T("Trimming Settings")</legend>
<div id="auditTrailAutoTrimthresholdSetting"> <div id="audittrail-trimming-retentionperiod-setting">
@Html.LabelFor(m => m.Threshold, T("Auto-trim threshold")) @Html.LabelFor(m => m.RetentionPeriod, T("Retention period"))
@Html.TextBoxFor(m => m.Threshold, new { @class = "text small" }) @Html.TextBoxFor(m => m.RetentionPeriod, new { @class = "text small" })
<span class="hint">@T("Specify the number of days of audit log data to retain.")</span> <span class="hint">@T("The number of days of audit log data to retain.")</span>
</div> </div>
</fieldset> </fieldset>