mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 19:04:51 +08:00
#16825: Exception in background task.
Return null for authenticated user if there is none set and there's no HttpContext. Somehow the correct owner is already being assigned, so the previously created OwnedScheduledTaskHandler was unnecessary. --HG-- branch : dev
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
using System;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Security;
|
||||
using Orchard.Tasks.Scheduling;
|
||||
|
||||
namespace Orchard.Core.Common.Scheduling {
|
||||
public abstract class OwnedScheduledTaskHandler : IScheduledTaskHandler {
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
|
||||
protected OwnedScheduledTaskHandler(IOrchardServices orchardServices) {
|
||||
_orchardServices = orchardServices;
|
||||
}
|
||||
|
||||
protected void SetCurrentUser(ContentItem contentItem) {
|
||||
IUser owner = null;
|
||||
var commonPart = contentItem.As<CommonPart>();
|
||||
if (commonPart != null) {
|
||||
owner = commonPart.Owner;
|
||||
}
|
||||
if (owner == null) {
|
||||
var superUser = _orchardServices.WorkContext.CurrentSite.SuperUser;
|
||||
owner = _orchardServices.WorkContext.Resolve<IMembershipService>().GetUser(superUser);
|
||||
}
|
||||
_orchardServices.WorkContext.Resolve<IAuthenticationService>().SetAuthenticatedUserForRequest(owner);
|
||||
}
|
||||
|
||||
public abstract void Process(ScheduledTaskContext context);
|
||||
}
|
||||
}
|
@@ -228,7 +228,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Common\Module.txt" />
|
||||
<Compile Include="Common\Scheduling\OwnedScheduledTaskHandler.cs" />
|
||||
<Content Include="Common\Views\DefinitionTemplates\BodyTypePartSettings.cshtml" />
|
||||
<Content Include="Common\Views\DefinitionTemplates\BodyPartSettings.cshtml" />
|
||||
<Content Include="Common\Views\Fields.Common.Text.cshtml" />
|
||||
|
@@ -1,29 +1,27 @@
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Common.Scheduling;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Tasks.Scheduling;
|
||||
|
||||
namespace Orchard.ArchiveLater.Handlers {
|
||||
[UsedImplicitly]
|
||||
public class UnpublishingTaskHandler : OwnedScheduledTaskHandler {
|
||||
public class UnpublishingTaskHandler : IScheduledTaskHandler {
|
||||
private readonly IContentManager _contentManager;
|
||||
|
||||
public UnpublishingTaskHandler(IContentManager contentManager, IOrchardServices orchardServices) : base(orchardServices) {
|
||||
public UnpublishingTaskHandler(IContentManager contentManager, IOrchardServices orchardServices) {
|
||||
_contentManager = contentManager;
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public override void Process(ScheduledTaskContext context) {
|
||||
public void Process(ScheduledTaskContext context) {
|
||||
if (context.Task.TaskType == "Unpublish") {
|
||||
Logger.Information("Unpublishing item #{0} version {1} scheduled at {2} utc",
|
||||
context.Task.ContentItem.Id,
|
||||
context.Task.ContentItem.Version,
|
||||
context.Task.ScheduledUtc);
|
||||
|
||||
SetCurrentUser(context.Task.ContentItem);
|
||||
_contentManager.Unpublish(context.Task.ContentItem);
|
||||
}
|
||||
}
|
||||
|
@@ -1,29 +1,27 @@
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Common.Scheduling;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Tasks.Scheduling;
|
||||
|
||||
namespace Orchard.PublishLater.Handlers {
|
||||
[UsedImplicitly]
|
||||
public class PublishingTaskHandler : OwnedScheduledTaskHandler {
|
||||
public class PublishingTaskHandler : IScheduledTaskHandler {
|
||||
private readonly IContentManager _contentManager;
|
||||
|
||||
public PublishingTaskHandler(IContentManager contentManager, IOrchardServices orchardServices) : base(orchardServices) {
|
||||
public PublishingTaskHandler(IContentManager contentManager, IOrchardServices orchardServices) {
|
||||
_contentManager = contentManager;
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public override void Process(ScheduledTaskContext context) {
|
||||
public void Process(ScheduledTaskContext context) {
|
||||
if (context.Task.TaskType == "Publish") {
|
||||
Logger.Information("Publishing item #{0} version {1} scheduled at {2} utc",
|
||||
context.Task.ContentItem.Id,
|
||||
context.Task.ContentItem.Version,
|
||||
context.Task.ScheduledUtc);
|
||||
|
||||
SetCurrentUser(context.Task.ContentItem);
|
||||
_contentManager.Publish(context.Task.ContentItem);
|
||||
}
|
||||
}
|
||||
|
@@ -70,7 +70,7 @@ namespace Orchard.Security.Providers {
|
||||
return _signedInUser;
|
||||
|
||||
var httpContext = _httpContextAccessor.Current();
|
||||
if (!httpContext.Request.IsAuthenticated || !(httpContext.User.Identity is FormsIdentity)) {
|
||||
if (httpContext == null || !httpContext.Request.IsAuthenticated || !(httpContext.User.Identity is FormsIdentity)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user