Skip to content

Commit ee5f537

Browse files
Merge pull request dnnsoftware#6560 from tvatavuk/develop
Fix HtmlModule 10 upgrade issues with localized sites
2 parents 7a44029 + b818397 commit ee5f537

10 files changed

Lines changed: 588 additions & 303 deletions

File tree

DNN Platform/Modules/HTML/Components/HtmlTextController.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ namespace DotNetNuke.Modules.Html
88
using System.Collections.Generic;
99
using System.Diagnostics.CodeAnalysis;
1010
using System.Linq;
11-
using System.Reflection;
1211
using System.Text;
1312
using System.Text.RegularExpressions;
1413
using System.Web;
@@ -20,7 +19,6 @@ namespace DotNetNuke.Modules.Html
2019
using DotNetNuke.Common.Utilities;
2120
using DotNetNuke.Entities.Content.Taxonomy;
2221
using DotNetNuke.Entities.Content.Workflow;
23-
using DotNetNuke.Entities.Content.Workflow.Entities;
2422
using DotNetNuke.Entities.Content.Workflow.Repositories;
2523
using DotNetNuke.Entities.Modules;
2624
using DotNetNuke.Entities.Portals;
@@ -29,7 +27,6 @@ namespace DotNetNuke.Modules.Html
2927
using DotNetNuke.Internal.SourceGenerators;
3028
using DotNetNuke.Modules.Html.Components;
3129
using DotNetNuke.Security;
32-
using DotNetNuke.Security.Permissions;
3330
using DotNetNuke.Security.Roles;
3431
using DotNetNuke.Services.Exceptions;
3532
using DotNetNuke.Services.Localization;
@@ -89,8 +86,8 @@ public static string FormatHtmlText(int moduleId, string content, HtmlModuleSett
8986
}
9087

9188
// manage relative paths
92-
content = ManageRelativePaths(content, portalSettings.HomeDirectory, "src", portalSettings.PortalId);
93-
content = ManageRelativePaths(content, portalSettings.HomeDirectory, "background", portalSettings.PortalId);
89+
content = ManageRelativePaths(content, portalSettings.HomeDirectory, "src");
90+
content = ManageRelativePaths(content, portalSettings.HomeDirectory, "background");
9491

9592
return content;
9693
}
@@ -551,9 +548,13 @@ public string UpgradeModule(string version)
551548
case "06.02.00":
552549
this.AddNotificationTypes();
553550
break;
551+
552+
case "10.00.00":
553+
MigrateHelper.MigrateHtmlWorkflows();
554+
break;
554555
}
555556

556-
return string.Empty;
557+
return "Success";
557558
}
558559

559560
private static void AddHtmlNotification(string subject, string body, UserInfo user)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information
4+
5+
namespace DotNetNuke.Modules.Html.Components
6+
{
7+
using System;
8+
using System.Collections.Generic;
9+
using System.Linq;
10+
11+
using DotNetNuke.Common.Utilities;
12+
using DotNetNuke.Services.Localization;
13+
14+
/// <summary>
15+
/// Provides helper methods for retrieving localization values for HTML module content workflow states.
16+
/// </summary>
17+
public class LocalizationHelper
18+
{
19+
/// <summary>
20+
/// Returns all possible localization values for a given key across all available languages.
21+
/// </summary>
22+
/// <param name="key">The content workflow state key to localize.</param>
23+
/// <returns>A list of localized values for the specified key in all available languages.</returns>
24+
public List<string> StateLocalizations(string key)
25+
{
26+
return this.GetLanguages().Select(language => Localization.GetString(key, Localization.GlobalResourceFile, language.Key)).ToList();
27+
}
28+
29+
/// <summary>
30+
/// Gets a dictionary of all available languages in the system, keyed by culture code.
31+
/// </summary>
32+
/// <returns>
33+
/// A <see cref="Dictionary{TKey, TValue}"/> where the key is the culture code and the value is a <see cref="Locale"/> object.
34+
/// </returns>
35+
private Dictionary<string, Locale> GetLanguages()
36+
{
37+
return CBO.FillDictionary("CultureCode", DotNetNuke.Data.DataProvider.Instance().ExecuteReader("GetLanguages"), new Dictionary<string, Locale>(StringComparer.OrdinalIgnoreCase));
38+
}
39+
}
40+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information
4+
5+
namespace DotNetNuke.Modules.Html.Components
6+
{
7+
/// <summary>
8+
/// Provides helper methods for migrating HTML workflows and related database schema changes.
9+
/// </summary>
10+
public class MigrateHelper
11+
{
12+
/// <summary>
13+
/// Executes the migration of HTML workflows, including running the migration procedure,
14+
/// dropping obsolete tables and procedures, and adding required foreign keys.
15+
/// </summary>
16+
public static void MigrateHtmlWorkflows()
17+
{
18+
var db = Data.DataProvider.Instance();
19+
var databaseOwner = db.DatabaseOwner;
20+
var objectQualifier = db.ObjectQualifier;
21+
22+
var localizationHelper = new LocalizationHelper();
23+
24+
// "Published|veröffentlicht|Publicado|Publié|Pubblicato|Publiceren"
25+
var publishedLocalizations = string.Join("|", localizationHelper.StateLocalizations("DefaultWorkflowState3.StateName"));
26+
27+
// "Draft|Entwurf|Borrador|Brouillon|Bozza|Concept"
28+
var draftLocalizations = string.Join("|", localizationHelper.StateLocalizations("DefaultWorkflowState1.StateName"));
29+
30+
// 1. Execute the migration procedure
31+
db.ExecuteNonQuery("MigrateHtmlWorkflows", publishedLocalizations, draftLocalizations);
32+
33+
// 2. Add FK_HtmlText_WorkflowStates if it does not exist
34+
db.ExecuteSQL($@"
35+
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'FK_{objectQualifier}HtmlText_{objectQualifier}WorkflowStates') AND parent_object_id = OBJECT_ID(N'{databaseOwner}{objectQualifier}HtmlText'))
36+
ALTER TABLE {databaseOwner}{objectQualifier}HtmlText WITH NOCHECK ADD CONSTRAINT FK_{objectQualifier}HtmlText_{objectQualifier}WorkflowStates FOREIGN KEY (StateID) REFERENCES {databaseOwner}{objectQualifier}ContentWorkflowStates (StateID);
37+
");
38+
39+
// 3. Add FK_HtmlTextLog_WorkflowStates if it does not exist
40+
db.ExecuteSQL($@"
41+
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'FK_{objectQualifier}HtmlTextLog_{objectQualifier}WorkflowStates') AND parent_object_id = OBJECT_ID(N'{databaseOwner}{objectQualifier}HtmlTextLog'))
42+
ALTER TABLE {databaseOwner}{objectQualifier}HtmlTextLog WITH NOCHECK ADD CONSTRAINT FK_{objectQualifier}HtmlTextLog_{objectQualifier}WorkflowStates FOREIGN KEY (StateID) REFERENCES {databaseOwner}{objectQualifier}ContentWorkflowStates (StateID);
43+
");
44+
45+
// 4. Enable HtmlText constraints after checking existing data
46+
db.ExecuteSQL($@"
47+
ALTER TABLE {databaseOwner}{objectQualifier}HtmlText WITH CHECK CHECK CONSTRAINT FK_{objectQualifier}HtmlText_{objectQualifier}WorkflowStates;
48+
");
49+
50+
// 5. Enable HtmlTextLog constraints after checking existing data
51+
db.ExecuteSQL($@"
52+
ALTER TABLE {databaseOwner}{objectQualifier}HtmlTextLog WITH CHECK CHECK CONSTRAINT FK_{objectQualifier}HtmlTextLog_{objectQualifier}WorkflowStates;
53+
");
54+
55+
// 6. Drop the migration procedure if it exists
56+
db.ExecuteSQL($@"
57+
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{databaseOwner}{objectQualifier}MigrateHtmlWorkflows') AND type in (N'P', N'PC'))
58+
DROP PROCEDURE {databaseOwner}{objectQualifier}MigrateHtmlWorkflows;
59+
");
60+
61+
// 7. Drop WorkflowStatePermission table if it exists
62+
db.ExecuteSQL($@"
63+
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'{databaseOwner}{objectQualifier}WorkflowStatePermission') AND OBJECTPROPERTY(id, N'IsTable') = 1)
64+
DROP TABLE {databaseOwner}{objectQualifier}WorkflowStatePermission;
65+
");
66+
67+
// 8. Drop WorkflowStates table if it exists
68+
db.ExecuteSQL($@"
69+
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{databaseOwner}{objectQualifier}WorkflowStates') AND type in (N'U'))
70+
DROP TABLE {databaseOwner}{objectQualifier}WorkflowStates;
71+
");
72+
73+
// 9. Drop Workflow table if it exists
74+
db.ExecuteSQL($@"
75+
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{databaseOwner}{objectQualifier}Workflow') AND type in (N'U'))
76+
DROP TABLE {databaseOwner}{objectQualifier}Workflow;
77+
");
78+
}
79+
}
80+
}

DNN Platform/Modules/HTML/DotNetNuke.Modules.Html.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@
142142
<Compile Include="Components\HtmlTextLogInfo.cs" />
143143
<Compile Include="Components\HtmlTextUserController.cs" />
144144
<Compile Include="Components\HtmlTextUserInfo.cs" />
145+
<Compile Include="Components\LocalizationHelper.cs" />
146+
<Compile Include="Components\MigrateHelper.cs" />
145147
<Compile Include="EditHtml.ascx.cs">
146148
<DependentUpon>EditHtml.ascx</DependentUpon>
147149
<SubType>ASPXCodeBehind</SubType>
@@ -216,9 +218,10 @@
216218
<None Include="Providers\DataProviders\SqlDataProvider\05.02.00.SqlDataProvider" />
217219
<None Include="Providers\DataProviders\SqlDataProvider\05.02.01.SqlDataProvider" />
218220
<None Include="Providers\DataProviders\SqlDataProvider\05.05.00.SqlDataProvider" />
219-
<Content Include="Providers\DataProviders\SqlDataProvider\07.02.01.SqlDataProvider" />
220-
<Content Include="Providers\DataProviders\SqlDataProvider\10.00.00.SqlDataProvider" />
221221
<None Include="Providers\DataProviders\SqlDataProvider\06.01.00.SqlDataProvider" />
222+
<None Include="Providers\DataProviders\SqlDataProvider\07.02.01.SqlDataProvider" />
223+
<None Include="Providers\DataProviders\SqlDataProvider\10.00.00.SqlDataProvider" />
224+
<None Include="Providers\DataProviders\SqlDataProvider\10.00.02.SqlDataProvider" />
222225
<None Include="Providers\DataProviders\SqlDataProvider\Uninstall.SqlDataProvider" />
223226
<Content Include="web.config" />
224227
</ItemGroup>

DNN Platform/Modules/HTML/EditHtml.ascx.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,8 @@ private void DisplayInitialContent(WorkflowState firstState)
653653
private string FormatContent(string htmlContent)
654654
{
655655
var strContent = HttpUtility.HtmlDecode(htmlContent);
656-
strContent = HtmlTextController.ManageRelativePaths(strContent, this.PortalSettings.HomeDirectory, "src", this.PortalId);
657-
strContent = HtmlTextController.ManageRelativePaths(strContent, this.PortalSettings.HomeDirectory, "background", this.PortalId);
656+
strContent = HtmlTextController.ManageRelativePaths(strContent, this.PortalSettings.HomeDirectory, "src");
657+
strContent = HtmlTextController.ManageRelativePaths(strContent, this.PortalSettings.HomeDirectory, "background");
658658
return HttpUtility.HtmlEncode(strContent);
659659
}
660660

0 commit comments

Comments
 (0)