mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-21 11:17:28 +08:00
Merge pull request #6604 from infofromca/timerNull
Fixed Timer activity throws NRE Fixes 6240 Fixes 6445
This commit is contained in:
@@ -4,9 +4,11 @@ using System.Linq;
|
|||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.Environment.Extensions;
|
using Orchard.Environment.Extensions;
|
||||||
|
using Orchard.Exceptions;
|
||||||
using Orchard.Forms.Services;
|
using Orchard.Forms.Services;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.Localization.Services;
|
using Orchard.Localization.Services;
|
||||||
|
using Orchard.Logging;
|
||||||
using Orchard.Services;
|
using Orchard.Services;
|
||||||
using Orchard.Tasks;
|
using Orchard.Tasks;
|
||||||
using Orchard.Workflows.Models;
|
using Orchard.Workflows.Models;
|
||||||
@@ -122,20 +124,30 @@ namespace Orchard.Workflows.Activities {
|
|||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
_workflowManager = workflowManager;
|
_workflowManager = workflowManager;
|
||||||
_awaitingActivityRepository = awaitingActivityRepository;
|
_awaitingActivityRepository = awaitingActivityRepository;
|
||||||
|
Logger = NullLogger.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ILogger Logger { get; set; }
|
||||||
public void Sweep() {
|
public void Sweep() {
|
||||||
var awaiting = _awaitingActivityRepository.Table.Where(x => x.ActivityRecord.Name == "Timer").ToList();
|
var awaiting = _awaitingActivityRepository.Table.Where(x => x.ActivityRecord.Name == "Timer").ToList();
|
||||||
|
|
||||||
|
|
||||||
foreach (var action in awaiting) {
|
foreach (var action in awaiting) {
|
||||||
var contentItem = _contentManager.Get(action.WorkflowRecord.ContentItemRecord.Id, VersionOptions.Latest);
|
try {
|
||||||
|
var contentItem = action.WorkflowRecord.ContentItemRecord != null ? _contentManager.Get(action.WorkflowRecord.ContentItemRecord.Id, VersionOptions.Latest) : null;
|
||||||
var tokens = new Dictionary<string, object> { { "Content", contentItem } };
|
var tokens = new Dictionary<string, object> { { "Content", contentItem } };
|
||||||
var workflowState = FormParametersHelper.FromJsonString(action.WorkflowRecord.State);
|
var workflowState = FormParametersHelper.FromJsonString(action.WorkflowRecord.State);
|
||||||
workflowState.TimerActivity_StartedUtc = null;
|
workflowState.TimerActivity_StartedUtc = null;
|
||||||
action.WorkflowRecord.State = FormParametersHelper.ToJsonString(workflowState);
|
action.WorkflowRecord.State = FormParametersHelper.ToJsonString(workflowState);
|
||||||
_workflowManager.TriggerEvent("Timer", contentItem, () => tokens);
|
_workflowManager.TriggerEvent("Timer", contentItem, () => tokens);
|
||||||
}
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
if (ex.IsFatal()) {
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
Logger.Error(ex, "TimerBackgroundTask: Error while processing background task \"{0}\".", action.ActivityRecord.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user