Updates the GetContentForExpiration, GetContentForRelease to ignore published/trashed flags so that callers can deal with those status, adds method to the repo to clear any schedule older than a given date.
This commit is contained in:
@@ -7,6 +7,12 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
public interface IDocumentRepository : IContentRepository<int, IContent>, IReadRepository<Guid, IContent>
|
||||
{
|
||||
/// <summary>
|
||||
/// Clears the publishing schedule for all entries before this date
|
||||
/// </summary>
|
||||
/// <param name="date"></param>
|
||||
void ClearSchedule(DateTime date);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of <see cref="IContent"/> objects, which has an expiration date less than or equal to today.
|
||||
/// </summary>
|
||||
|
||||
@@ -907,22 +907,24 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
|
||||
#region Schedule
|
||||
|
||||
/// <inheritdoc />
|
||||
public void ClearSchedule(DateTime date)
|
||||
{
|
||||
var sql = Sql().Delete<ContentScheduleDto>().Where<ContentScheduleDto>(x => x.Date <= date);
|
||||
Database.Execute(sql);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IContent> GetContentForRelease(DateTime date)
|
||||
{
|
||||
var action = ContentScheduleChange.Start.ToString();
|
||||
|
||||
// fixme/review - code would blow if more than 2000 items
|
||||
// fixme/review - isn't this simpler?
|
||||
var sql = GetBaseQuery(QueryType.Many)
|
||||
.WhereIn<NodeDto>(x => x.NodeId, Sql()
|
||||
.Select<ContentScheduleDto>(x => x.NodeId)
|
||||
.From<ContentScheduleDto>()
|
||||
.Where<ContentScheduleDto>(x => x.Action == action && x.Date <= date));
|
||||
|
||||
sql.Where<NodeDto>(x => !x.Trashed); // fixme/review - shouldn't we exclude trashed nodes?
|
||||
sql.Where<DocumentDto>(x => !x.Published);
|
||||
|
||||
|
||||
AddGetByQueryOrderBy(sql);
|
||||
|
||||
return MapDtosToContent(Database.Fetch<DocumentDto>(sql));
|
||||
@@ -940,8 +942,6 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
.From<ContentScheduleDto>()
|
||||
.Where<ContentScheduleDto>(x => x.Action == action && x.Date <= date));
|
||||
|
||||
sql.Where<DocumentDto>(x => x.Published);
|
||||
|
||||
AddGetByQueryOrderBy(sql);
|
||||
|
||||
return MapDtosToContent(Database.Fetch<DocumentDto>(sql));
|
||||
|
||||
@@ -1173,7 +1173,7 @@ namespace Umbraco.Core.Services.Implement
|
||||
|
||||
var now = date;
|
||||
|
||||
foreach (var d in GetContentForRelease(now))
|
||||
foreach (var d in _documentRepository.GetContentForRelease(now))
|
||||
{
|
||||
PublishResult result;
|
||||
if (d.ContentType.VariesByCulture())
|
||||
@@ -1188,13 +1188,17 @@ namespace Umbraco.Core.Services.Implement
|
||||
{
|
||||
//Clear this schedule for this culture
|
||||
d.ContentSchedule.Clear(c, ContentScheduleChange.Start, now);
|
||||
//set the culture to be published
|
||||
d.PublishCulture(c);
|
||||
if (!d.Trashed)
|
||||
d.PublishCulture(c); //set the culture to be published
|
||||
}
|
||||
|
||||
if (pendingCultures.Count > 0)
|
||||
{
|
||||
result = SavePublishing(d, d.WriterId);
|
||||
if (!d.Trashed)
|
||||
result = SavePublishing(d, d.WriterId);
|
||||
else
|
||||
result = new PublishResult(PublishResultType.FailedPublishPathNotPublished, evtMsgs, d);
|
||||
|
||||
if (result.Success == false)
|
||||
Logger.Error<ContentService>(null, "Failed to publish document id={DocumentId}, reason={Reason}.", d.Id, result.Result);
|
||||
yield return result;
|
||||
@@ -1204,14 +1208,18 @@ namespace Umbraco.Core.Services.Implement
|
||||
{
|
||||
//Clear this schedule
|
||||
d.ContentSchedule.Clear(ContentScheduleChange.Start, now);
|
||||
result = SaveAndPublish(d, userId: d.WriterId);
|
||||
if (!d.Trashed)
|
||||
result = SaveAndPublish(d, userId: d.WriterId);
|
||||
else
|
||||
result = new PublishResult(PublishResultType.FailedPublishPathNotPublished, evtMsgs, d);
|
||||
|
||||
if (result.Success == false)
|
||||
Logger.Error<ContentService>(null, "Failed to publish document id={DocumentId}, reason={Reason}.", d.Id, result.Result);
|
||||
yield return result;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var d in GetContentForExpiration(now))
|
||||
foreach (var d in _documentRepository.GetContentForExpiration(now))
|
||||
{
|
||||
PublishResult result;
|
||||
if (d.ContentType.VariesByCulture())
|
||||
@@ -1251,6 +1259,8 @@ namespace Umbraco.Core.Services.Implement
|
||||
|
||||
}
|
||||
|
||||
_documentRepository.ClearSchedule(now);
|
||||
|
||||
scope.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user