Skip to content

Commit 02549d2

Browse files
authored
Merge pull request #1325 from johnhenley/issues/don't-overwrite-templates-1312
FIX: Don't overwrite existing templates
2 parents 982f8af + 35a85bf commit 02549d2

File tree

2 files changed

+40
-38
lines changed

2 files changed

+40
-38
lines changed

Dnn.CommunityForums/class/ForumsConfig.cs

+37-38
Original file line numberDiff line numberDiff line change
@@ -334,48 +334,47 @@ internal void Install_Or_Upgrade_MoveTemplates_080000()
334334
if (!System.IO.Directory.Exists(themeFolder.FullName + "/templates"))
335335
{
336336
System.IO.Directory.CreateDirectory(themeFolder.FullName + "/templates");
337-
}
338-
}
339-
340-
TemplateController tc = new TemplateController();
341-
foreach (TemplateInfo templateInfo in tc.Template_List(-1, -1))
342-
{
343-
/* during upgrade, explicitly (re-)load template text from database rather than Template_List API since API loads template using fallback/default logic and doesn't yet have the upgraded template text */
344-
/* if installing version 8.2 or greater, only convert these specific templates */
345-
if ((new Version(DesktopModuleController.GetDesktopModuleByFriendlyName(Globals.ModuleFriendlyName).Version) < new Version(8, 2)) ||
346-
((templateInfo.TemplateType == Templates.TemplateTypes.ForumView) ||
347-
(templateInfo.TemplateType == Templates.TemplateTypes.TopicView) ||
348-
(templateInfo.TemplateType == Templates.TemplateTypes.TopicsView) ||
349-
(templateInfo.TemplateType == Templates.TemplateTypes.TopicForm) ||
350-
(templateInfo.TemplateType == Templates.TemplateTypes.Profile) ||
351-
(templateInfo.TemplateType == Templates.TemplateTypes.PostInfo) ||
352-
(templateInfo.TemplateType == Templates.TemplateTypes.QuickReplyForm)))
353-
{
354-
IDataReader dr = DataProvider.Instance().Templates_Get(templateInfo.TemplateId, templateInfo.PortalId, templateInfo.ModuleId);
355-
while (dr.Read())
337+
TemplateController tc = new TemplateController();
338+
foreach (TemplateInfo templateInfo in tc.Template_List(-1, -1))
356339
{
357-
try
340+
/* during upgrade, explicitly (re-)load template text from database rather than Template_List API since API loads template using fallback/default logic and doesn't yet have the upgraded template text */
341+
/* if installing version 8.2 or greater, only convert these specific templates */
342+
if ((Globals.ModuleVersion < new Version(8, 2)) ||
343+
((templateInfo.TemplateType == Templates.TemplateTypes.ForumView) ||
344+
(templateInfo.TemplateType == Templates.TemplateTypes.TopicView) ||
345+
(templateInfo.TemplateType == Templates.TemplateTypes.TopicsView) ||
346+
(templateInfo.TemplateType == Templates.TemplateTypes.TopicForm) ||
347+
(templateInfo.TemplateType == Templates.TemplateTypes.Profile) ||
348+
(templateInfo.TemplateType == Templates.TemplateTypes.PostInfo) ||
349+
(templateInfo.TemplateType == Templates.TemplateTypes.QuickReplyForm)))
358350
{
359-
/* convert only legacy html portion of the template and save without encoding */
360-
string template = Convert.ToString(dr["Template"]).Replace("[TRESX:", "[RESX:");
361-
if (template.Contains("<html>"))
351+
IDataReader dr = DataProvider.Instance().Templates_Get(templateInfo.TemplateId, templateInfo.PortalId, templateInfo.ModuleId);
352+
while (dr.Read())
362353
{
363-
string sHTML;
364-
var xDoc = new System.Xml.XmlDocument();
365-
xDoc.LoadXml(template);
366-
System.Xml.XmlNode xNode;
367-
System.Xml.XmlNode xRoot = xDoc.DocumentElement;
368-
xNode = xRoot.SelectSingleNode("/template/html");
369-
sHTML = xNode.InnerText;
370-
template = sHTML;
354+
try
355+
{
356+
/* convert only legacy html portion of the template and save without encoding */
357+
string template = Convert.ToString(dr["Template"]).Replace("[TRESX:", "[RESX:");
358+
if (template.Contains("<html>"))
359+
{
360+
string sHTML;
361+
var xDoc = new System.Xml.XmlDocument();
362+
xDoc.LoadXml(template);
363+
System.Xml.XmlNode xNode;
364+
System.Xml.XmlNode xRoot = xDoc.DocumentElement;
365+
xNode = xRoot.SelectSingleNode("/template/html");
366+
sHTML = xNode.InnerText;
367+
template = sHTML;
368+
}
369+
370+
templateInfo.Template = System.Net.WebUtility.HtmlDecode(template);
371+
tc.Template_Save(templateInfo);
372+
}
373+
catch (Exception ex)
374+
{
375+
DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
376+
}
371377
}
372-
373-
templateInfo.Template = System.Net.WebUtility.HtmlDecode(template);
374-
tc.Template_Save(templateInfo);
375-
}
376-
catch (Exception ex)
377-
{
378-
DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
379378
}
380379
}
381380
}

Dnn.CommunityForums/class/Globals.cs

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
namespace DotNetNuke.Modules.ActiveForums
2222
{
2323
using System;
24+
using DotNetNuke.Entities.Modules;
2425

2526
#region Enumerations
2627

@@ -174,6 +175,8 @@ public static string DefaultAnonRoles
174175
public const string LikeNotificationTypeDescription = Globals.ModuleFriendlyName + " Like Notification";
175176
public const string PinNotificationType = "DCF-PinNotification";
176177
public const string PinNotificationTypeDescription = Globals.ModuleFriendlyName + " Pin Notification";
178+
179+
public static Version ModuleVersion => new Version(DesktopModuleController.GetDesktopModuleByFriendlyName(Globals.ModuleFriendlyName).Version);
177180
}
178181

179182
public class SettingKeys

0 commit comments

Comments
 (0)