Skip to content

Commit 984328c

Browse files
committed
Readding the migration step that updates the existing Send Email activities
1 parent 6df533d commit 984328c

File tree

4 files changed

+146
-0
lines changed

4 files changed

+146
-0
lines changed

src/Orchard.Web/Modules/Upgrade/AdminMenu.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public void GetNavigation(NavigationBuilder builder)
1717
.Add(T("Upgrade to 1.10.3"), "0", menu => menu.Action("Index", "Route", new { area = "Upgrade" })
1818
.Add(T("Projections (1.10.3)"), "1.0", item => item.Action("Index", "Projections", new { area = "Upgrade" }).LocalNav().Permission(StandardPermissions.SiteOwner))
1919
.Add(T("Infoset (1.8)"), "1.0", item => item.Action("Index", "Infoset", new { area = "Upgrade" }).LocalNav().Permission(StandardPermissions.SiteOwner))
20+
.Add(T("Messaging (1.8)"), "1.1", item => item.Action("Index", "Messaging", new { area = "Upgrade" }).LocalNav().Permission(StandardPermissions.SiteOwner))
2021
.Add(T("Media (1.7)"), "2", item => item.Action("Index", "Media", new { area = "Upgrade" }).LocalNav().Permission(StandardPermissions.SiteOwner))
2122
.Add(T("Taxonomies (1.7)"), "3", item => item.Action("Index", "Taxonomy", new { area = "Upgrade" }).LocalNav().Permission(StandardPermissions.SiteOwner))
2223
.Add(T("Taxonomies (1.10)"), "3", item => item.Action("Index110", "Taxonomy", new { area = "Upgrade" }).LocalNav().Permission(StandardPermissions.SiteOwner))
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
using System.Web.Mvc;
2+
using Newtonsoft.Json;
3+
using Orchard;
4+
using Orchard.Data;
5+
using Orchard.Email.Models;
6+
using Orchard.Localization;
7+
using Orchard.Security;
8+
using Orchard.UI.Admin;
9+
using Orchard.UI.Notify;
10+
using Orchard.Workflows.Models;
11+
using Upgrade.Services;
12+
13+
namespace Upgrade.Controllers
14+
{
15+
[Admin]
16+
public class MessagingController : Controller
17+
{
18+
private readonly IUpgradeService _upgradeService;
19+
private readonly IOrchardServices _orchardServices;
20+
private readonly IRepository<ActivityRecord> _repository;
21+
22+
public MessagingController(
23+
IUpgradeService upgradeService,
24+
IOrchardServices orchardServices,
25+
IRepository<ActivityRecord> repository)
26+
{
27+
_upgradeService = upgradeService;
28+
_orchardServices = orchardServices;
29+
_repository = repository;
30+
}
31+
32+
public Localizer T { get; set; }
33+
34+
public ActionResult Index()
35+
{
36+
var found = false;
37+
var activityTable = _upgradeService.GetPrefixedTableName("Orchard_Workflows_ActivityRecord");
38+
if (_upgradeService.TableExists(activityTable))
39+
{
40+
_upgradeService.ExecuteReader("SELECT * FROM " + activityTable + " WHERE Name = 'SendEmail'",
41+
(reader, connection) =>
42+
{
43+
found = true;
44+
});
45+
46+
if (!found)
47+
{
48+
_orchardServices.Notifier.Warning(T("This step is unnecessary as no Send Email activities were found."));
49+
}
50+
}
51+
else
52+
{
53+
_orchardServices.Notifier.Warning(T("This step appears unnecessary since it appears Orchard Workflows is not enabled."));
54+
}
55+
56+
return View();
57+
}
58+
59+
[HttpPost, ActionName("Index")]
60+
public ActionResult IndexPOST()
61+
{
62+
if (!_orchardServices.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not allowed to upgrade.")))
63+
return new HttpUnauthorizedResult();
64+
65+
var activityTable = _upgradeService.GetPrefixedTableName("Orchard_Workflows_ActivityRecord");
66+
if (_upgradeService.TableExists(activityTable))
67+
{
68+
_upgradeService.ExecuteReader("SELECT * FROM " + activityTable + " WHERE Name = 'SendEmail'",
69+
(reader, connection) =>
70+
{
71+
var record = _repository.Get((int)reader["Id"]);
72+
73+
if (record == null)
74+
{
75+
return;
76+
}
77+
78+
var state = JsonConvert.DeserializeAnonymousType(record.State, new
79+
{
80+
Body = "",
81+
Subject = "",
82+
Recipient = "",
83+
RecipientOther = "",
84+
});
85+
86+
var newState = new EmailMessage
87+
{
88+
Body = state.Body,
89+
Subject = state.Subject
90+
};
91+
92+
if (!newState.Body.StartsWith("<p "))
93+
{
94+
newState.Body =
95+
newState.Body
96+
+ System.Environment.NewLine;
97+
}
98+
99+
if (state.Recipient == "owner")
100+
{
101+
newState.Recipients = "{Content.Author.Email}";
102+
}
103+
else if (state.Recipient == "author")
104+
{
105+
newState.Recipients = "{User.Current.Email}";
106+
}
107+
else if (state.Recipient == "admin")
108+
{
109+
newState.Recipients = "{Site.SuperUser.Email}";
110+
}
111+
else if (state.Recipient == "other")
112+
{
113+
newState.Recipients = state.RecipientOther;
114+
}
115+
116+
record.State = JsonConvert.SerializeObject(newState);
117+
});
118+
119+
_orchardServices.Notifier.Success(T("Email activities updated successfully"));
120+
}
121+
else
122+
{
123+
_orchardServices.Notifier.Warning(T("No email activities were updated."));
124+
}
125+
126+
return RedirectToAction("Index");
127+
}
128+
}
129+
}

src/Orchard.Web/Modules/Upgrade/Upgrade.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@
192192
<Compile Include="Controllers\InfosetController.cs" />
193193
<Compile Include="Controllers\MediaController.cs" />
194194
<Compile Include="Controllers\MenuController.cs" />
195+
<Compile Include="Controllers\MessagingController.cs" />
195196
<Compile Include="Controllers\RouteController.cs" />
196197
<Compile Include="Controllers\TaxonomyController.cs" />
197198
<Compile Include="Services\IUpgradeService.cs" />
@@ -204,6 +205,7 @@
204205
<Content Include="Views\Infoset\Index.cshtml" />
205206
<Content Include="Views\Media\Index.cshtml" />
206207
<Content Include="Views\Menu\Index.cshtml" />
208+
<Content Include="Views\Messaging\Index.cshtml" />
207209
<Content Include="Views\Route\Index.cshtml" />
208210
<Content Include="Views\Taxonomy\Index.cshtml" />
209211
</ItemGroup>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@using Orchard.Utility.Extensions
2+
3+
@{ Layout.Title = T("Migrate Messaging").ToString(); }
4+
5+
@using (Html.BeginFormAntiForgeryPost()) {
6+
Html.ValidationSummary();
7+
<fieldset>
8+
<legend>@T("Migrating Email Activities:")</legend>
9+
<span class="hint">@T("This migration step will update the existing Send Email activities to use the new Message Queueing functionality.")</span>
10+
</fieldset>
11+
<fieldset>
12+
<button type="submit">@T("Migrate")</button>
13+
</fieldset>
14+
}

0 commit comments

Comments
 (0)