private string FriendlyString(EventForScheduling efs) { switch (efs) { case EventForScheduling.Creation: return(T("Creation").Text); case EventForScheduling.LatestUpdate: return(T("Latest Update").Text); default: return(string.Empty); } }
private IContentQuery <CommonPart> LatestDateQuery( IContentQuery <CommonPart> query, EventForScheduling eventToCheck, int days) { var latestDate = _clock.UtcNow - TimeSpan.FromDays(days); switch (eventToCheck) { case EventForScheduling.Creation: return(query.Where <CommonPartRecord>(cpr => cpr.CreatedUtc < latestDate)); case EventForScheduling.LatestUpdate: default: return(query.Where <CommonPartRecord>(cpr => cpr.ModifiedUtc < latestDate)); } }
private void Process( string typeName, EventForScheduling eventToCheck, int days, Action <ContentItem> gdprProcess, bool firstTimeTask) { // get the contentItems to process var commonPartsQuery = _contentManager.Query() .ForType(typeName) .ForVersion(VersionOptions.AllVersions) // even deleted ContentItems .ForPart <CommonPart>(); // we don't want to be pulling every ContentItem ever of this type. So, if we have processed things already // we pose a limit to the earliest date we will allow. if (!firstTimeTask) { commonPartsQuery = EarliestDateQuery(commonPartsQuery, eventToCheck, days); } commonPartsQuery = LatestDateQuery(commonPartsQuery, eventToCheck, days); var commonParts = commonPartsQuery .List() // becomes an IEnumerable ; var contentItems = commonParts .Select(cp => cp.ContentItem) // get the item .GroupBy(ci => ci.Id) // this line and the next basically do a Distinct() on the id .Select(group => group.First()); foreach (var item in contentItems) { // After we process the item, we should revert the date of its last update. // If we don't, we will end up processing this item again in the future, because // its latest update will have moved forward to the date of this process. var oldDate = item.As <CommonPart>().ModifiedUtc; gdprProcess(item); item.As <CommonPart>().ModifiedUtc = oldDate; } }