Skip to content

Commit

Permalink
Add outcome for when email failed (OrchardCMS#7825)
Browse files Browse the repository at this point in the history
  • Loading branch information
jardg authored and sebastienros committed Aug 31, 2017
1 parent 5ea4a7a commit 70adb18
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/Orchard.Web/Modules/Orchard.Email/Activities/EmailActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Orchard.Environment.Extensions;
using Orchard.Events;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Messaging.Services;
using Orchard.Workflows.Models;
using Orchard.Workflows.Services;
Expand All @@ -16,20 +17,22 @@ public interface IJobsQueueService : IEventHandler {
public class EmailActivity : Task {
private readonly IMessageService _messageService;
private readonly IJobsQueueService _jobsQueueService;
public ILogger Logger { get; set; }

public EmailActivity(
IMessageService messageService,
IJobsQueueService jobsQueueService
) {
_messageService = messageService;
_jobsQueueService = jobsQueueService;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
}

public Localizer T { get; set; }

public override IEnumerable<LocalizedString> GetPossibleOutcomes(WorkflowContext workflowContext, ActivityContext activityContext) {
return new[] { T("Done") };
return new[] { T("Done"), T("Failed") };
}

public override string Form {
Expand Down Expand Up @@ -69,17 +72,23 @@ public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowCon
{"NotifyReadEmail",notifyReadEmail }
};

var queued = activityContext.GetState<bool>("Queued");

if (!queued) {
_messageService.Send(SmtpMessageChannel.MessageType, parameters);
if (string.IsNullOrWhiteSpace(recipients)) {
Logger.Error("Email message doesn't have any recipient for Workflow {0}", workflowContext.Record.WorkflowDefinitionRecord.Name);
yield return T("Failed");
}
else {
var priority = activityContext.GetState<int>("Priority");
_jobsQueueService.Enqueue("IMessageService.Send", new { type = SmtpMessageChannel.MessageType, parameters = parameters }, priority);
}
var queued = activityContext.GetState<bool>("Queued");

yield return T("Done");
if (!queued) {
_messageService.Send(SmtpMessageChannel.MessageType, parameters);
}
else {
var priority = activityContext.GetState<int>("Priority");
_jobsQueueService.Enqueue("IMessageService.Send", new { type = SmtpMessageChannel.MessageType, parameters = parameters }, priority);
}

yield return T("Done");
}
}
}
}

0 comments on commit 70adb18

Please sign in to comment.