#16335: The post can be scheduled to publish at a past time

Work Item: 16335

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2011-11-09 16:21:26 -08:00
parent dbe908a717
commit 3f41484d53

View File

@@ -9,21 +9,25 @@ using Orchard.PublishLater.Services;
using Orchard.PublishLater.ViewModels; using Orchard.PublishLater.ViewModels;
using Orchard.Localization; using Orchard.Localization;
using System.Globalization; using System.Globalization;
using Orchard.Services;
namespace Orchard.PublishLater.Drivers { namespace Orchard.PublishLater.Drivers {
public class PublishLaterPartDriver : ContentPartDriver<PublishLaterPart> { public class PublishLaterPartDriver : ContentPartDriver<PublishLaterPart> {
private const string TemplateName = "Parts/PublishLater"; private const string TemplateName = "Parts/PublishLater";
private readonly IHttpContextAccessor _httpContextAccessor; private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IPublishLaterService _publishLaterService; private readonly IPublishLaterService _publishLaterService;
private readonly IClock _clock;
private const string DatePattern = "M/d/yyyy"; private const string DatePattern = "M/d/yyyy";
private const string TimePattern = "h:mm tt"; private const string TimePattern = "h:mm tt";
public PublishLaterPartDriver( public PublishLaterPartDriver(
IOrchardServices services, IOrchardServices services,
IHttpContextAccessor httpContextAccessor, IHttpContextAccessor httpContextAccessor,
IPublishLaterService publishLaterService) { IPublishLaterService publishLaterService,
IClock clock) {
_httpContextAccessor = httpContextAccessor; _httpContextAccessor = httpContextAccessor;
_publishLaterService = publishLaterService; _publishLaterService = publishLaterService;
_clock = clock;
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
Services = services; Services = services;
} }
@@ -70,8 +74,14 @@ namespace Orchard.PublishLater.Drivers {
// use an english culture as it is the one used by jQuery.datepicker by default // use an english culture as it is the one used by jQuery.datepicker by default
if (DateTime.TryParse(parseDateTime, CultureInfo.GetCultureInfo("en-US"), DateTimeStyles.AssumeLocal, out scheduled)) { if (DateTime.TryParse(parseDateTime, CultureInfo.GetCultureInfo("en-US"), DateTimeStyles.AssumeLocal, out scheduled)) {
model.ScheduledPublishUtc = part.ScheduledPublishUtc.Value = scheduled.ToUniversalTime(); model.ScheduledPublishUtc = part.ScheduledPublishUtc.Value = scheduled.ToUniversalTime();
if (model.ScheduledPublishUtc < _clock.UtcNow) {
updater.AddModelError("ScheduledPublishUtcDate", T("You cannot schedule a publishing date in the past"));
}
else {
_publishLaterService.Publish(model.ContentItem, model.ScheduledPublishUtc.Value); _publishLaterService.Publish(model.ContentItem, model.ScheduledPublishUtc.Value);
} }
}
else { else {
updater.AddModelError(Prefix, T("{0} is an invalid date and time", parseDateTime)); updater.AddModelError(Prefix, T("{0} is an invalid date and time", parseDateTime));
} }