Skip to content

Commit

Permalink
Update HtmlText to Content Workflow API
Browse files Browse the repository at this point in the history
  • Loading branch information
tvatavuk committed Jan 21, 2025
1 parent 5eb4a66 commit 08613ee
Show file tree
Hide file tree
Showing 11 changed files with 506 additions and 505 deletions.
131 changes: 66 additions & 65 deletions DNN Platform/Modules/HTML/Components/HtmlTextController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace DotNetNuke.Modules.Html
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
Expand All @@ -17,6 +19,8 @@ namespace DotNetNuke.Modules.Html
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Content.Taxonomy;
using DotNetNuke.Entities.Content.Workflow;
using DotNetNuke.Entities.Content.Workflow.Entities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Tabs;
Expand All @@ -35,12 +39,14 @@ namespace DotNetNuke.Modules.Html
using Microsoft.Extensions.DependencyInjection;

/// <summary>The HtmlTextController is the Controller class for managing HtmlText information the HtmlText module.</summary>
public partial class HtmlTextController : ModuleSearchBase, IPortable, IUpgradeable
public partial class HtmlTextController : ModuleSearchBase, IPortable, IUpgradeable, IVersionable
{
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:FieldNamesMustNotContainUnderscore", Justification = "Breaking Change")]
public const int MAX_DESCRIPTION_LENGTH = 100;
private const string PortalRootToken = "{{PortalRoot}}";

private readonly IWorkflowManager workflowManager = WorkflowManager.Instance;

/// <summary>Initializes a new instance of the <see cref="HtmlTextController"/> class.</summary>
public HtmlTextController()
: this(Globals.GetCurrentServiceProvider().GetRequiredService<INavigationManager>())
Expand Down Expand Up @@ -204,10 +210,14 @@ public string ReplaceWithRootToken(Match m)
/// <param name="itemID">The ID of the Item.</param>
public void DeleteHtmlText(int moduleID, int itemID)
{
var moduleVersion = this.GetHtmlText(moduleID, itemID).Version;

DataProvider.Instance().DeleteHtmlText(moduleID, itemID);

// refresh output cache
ModuleController.SynchronizeModule(moduleID);

TrackModuleModification(moduleID, moduleVersion);
}

/// <summary>GetAllHtmlText gets a collection of HtmlTextInfo objects for the Module and Workflow.</summary>
Expand Down Expand Up @@ -243,11 +253,9 @@ public HtmlTextInfo GetTopHtmlText(int moduleId, bool isPublished, int workflowI
// get proper state for workflow
htmlText.WorkflowID = workflowId;
htmlText.WorkflowName = "[REPAIR_WORKFLOW]";

var workflowStateController = new WorkflowStateController();
htmlText.StateID = htmlText.IsPublished
? workflowStateController.GetLastWorkflowStateID(workflowId)
: workflowStateController.GetFirstWorkflowStateID(workflowId);
? this.workflowManager.GetWorkflow(workflowId).LastState.StateID
: this.workflowManager.GetWorkflow(workflowId).FirstState.StateID;

// update object
this.UpdateHtmlText(htmlText, this.GetMaximumVersionHistory(htmlText.PortalID));
Expand All @@ -267,61 +275,13 @@ public HtmlTextInfo GetTopHtmlText(int moduleId, bool isPublished, int workflowI
/// <returns>A <see cref="KeyValuePair{TKey,TValue}"/> where the <see cref="KeyValuePair{TKey,TValue}.Key"/> is the workflow type, and the <see cref="KeyValuePair{TKey,TValue}.Value"/> is the workflow ID.</returns>
public KeyValuePair<string, int> GetWorkflow(int moduleId, int tabId, int portalId)
{
int workFlowId = Null.NullInteger;
string workFlowType = Null.NullString;
var tab = TabController.Instance.GetTab(tabId, portalId);

// get module settings
HtmlModuleSettings settings;
if (moduleId > -1)
{
var module = ModuleController.Instance.GetModule(moduleId, tabId, false);
var repo = new HtmlModuleSettingsRepository();
settings = repo.GetSettings(module);
}
else
{
settings = new HtmlModuleSettings();
}
var workFlowId = tab.StateID == Null.NullInteger
? TabWorkflowSettings.Instance.GetDefaultTabWorkflowId(PortalSettings.Current.PortalId)
: WorkflowStateManager.Instance.GetWorkflowState(tab.StateID).WorkflowID;

if (settings.WorkFlowID != Null.NullInteger)
{
workFlowId = settings.WorkFlowID;
workFlowType = "Module";
}

if (workFlowId == Null.NullInteger)
{
// if undefined at module level, get from tab settings
var tabSettings = TabController.Instance.GetTabSettings(tabId);
if (tabSettings["WorkflowID"] != null)
{
workFlowId = Convert.ToInt32(tabSettings["WorkflowID"]);
workFlowType = "Page";
}
}

if (workFlowId == Null.NullInteger)
{
// if undefined at tab level, get from portal settings
workFlowId = int.Parse(PortalController.GetPortalSetting("WorkflowID", portalId, "-1"));
workFlowType = "Site";
}

// if undefined at portal level, set portal default
if (workFlowId == Null.NullInteger)
{
var objWorkflow = new WorkflowStateController();
ArrayList arrWorkflows = objWorkflow.GetWorkflows(portalId);
foreach (WorkflowStateInfo objState in arrWorkflows)
{
// use direct publish as default
if (Null.IsNull(objState.PortalID) && objState.WorkflowName == "Direct Publish")
{
workFlowId = objState.WorkflowID;
workFlowType = "Module";
}
}
}
var workFlowType = WorkflowManager.Instance.GetWorkflow(workFlowId).WorkflowName;

return new KeyValuePair<string, int>(workFlowType, workFlowId);
}
Expand All @@ -331,7 +291,6 @@ public KeyValuePair<string, int> GetWorkflow(int moduleId, int tabId, int portal
/// <param name="maximumVersionHistory">The maximum number of versions to retain.</param>
public void UpdateHtmlText(HtmlTextInfo htmlContent, int maximumVersionHistory)
{
var workflowStateController = new WorkflowStateController();
bool blnCreateNewVersion = false;

// determine if we are creating a new version of content or updating an existing version
Expand All @@ -342,7 +301,7 @@ public void UpdateHtmlText(HtmlTextInfo htmlContent, int maximumVersionHistory)
HtmlTextInfo objContent = this.GetTopHtmlText(htmlContent.ModuleID, false, htmlContent.WorkflowID);
if (objContent != null)
{
if (objContent.StateID == workflowStateController.GetLastWorkflowStateID(htmlContent.WorkflowID))
if (objContent.StateID == this.workflowManager.GetWorkflow(htmlContent.WorkflowID).LastState.StateID)
{
blnCreateNewVersion = true;
}
Expand All @@ -355,7 +314,7 @@ public void UpdateHtmlText(HtmlTextInfo htmlContent, int maximumVersionHistory)
}

// determine if content is published
if (htmlContent.StateID == workflowStateController.GetLastWorkflowStateID(htmlContent.WorkflowID))
if (htmlContent.StateID == this.workflowManager.GetWorkflow(htmlContent.WorkflowID).LastState.StateID)
{
htmlContent.IsPublished = true;
}
Expand All @@ -382,6 +341,9 @@ public void UpdateHtmlText(HtmlTextInfo htmlContent, int maximumVersionHistory)
DataProvider.Instance().UpdateHtmlText(htmlContent.ItemID, htmlContent.Content, htmlContent.Summary, htmlContent.StateID, htmlContent.IsPublished, UserController.Instance.GetCurrentUserInfo().UserID);
}

// refresh to get version
htmlContent = this.GetHtmlText(htmlContent.ModuleID, htmlContent.ItemID);

// add log history
var logInfo = new HtmlTextLogInfo();
logInfo.ItemID = htmlContent.ItemID;
Expand All @@ -396,6 +358,10 @@ public void UpdateHtmlText(HtmlTextInfo htmlContent, int maximumVersionHistory)

// refresh output cache
ModuleController.SynchronizeModule(htmlContent.ModuleID);

var moduleVersion = htmlContent.Version < 1 ? 1 : htmlContent.Version;

TrackModuleModification(htmlContent.ModuleID, moduleVersion);
}

/// <summary>UpdateWorkFlow updates the currently active Workflow.</summary>
Expand Down Expand Up @@ -486,6 +452,37 @@ public void UpdateMaximumVersionHistory(int portalID, int maximumVersionHistory)
}
}

public void DeleteVersion(int moduleId, int version)
{
var htmlContent = this.GetAllHtmlText(moduleId).First(h => h.Version == version || h.Version == this.GetLatestVersion(moduleId));

this.DeleteHtmlText(moduleId, htmlContent.ItemID);
}

public int RollBackVersion(int moduleId, int version)
{
throw new NotImplementedException();
}

public void PublishVersion(int moduleId, int version)
{
var htmlContent = this.GetAllHtmlText(moduleId).First(h => h.Version == version || h.Version == this.GetLatestVersion(moduleId));
htmlContent.StateID = this.workflowManager.GetWorkflow(htmlContent.WorkflowID).LastState.StateID;
this.UpdateHtmlText(htmlContent, this.GetMaximumVersionHistory(htmlContent.PortalID));
}

public int GetPublishedVersion(int moduleId)
{
var htmlText = CBO.FillObject<HtmlTextInfo>(DataProvider.Instance().GetTopHtmlText(moduleId, true));
return htmlText.Version;
}

public int GetLatestVersion(int moduleId)
{
var htmlText = CBO.FillObject<HtmlTextInfo>(DataProvider.Instance().GetTopHtmlText(moduleId, false));
return htmlText.Version;
}

/// <inheritdoc />
public string ExportModule(int moduleId)
{
Expand All @@ -509,7 +506,6 @@ public string ExportModule(int moduleId)
public void ImportModule(int moduleID, string content, string version, int userId)
{
ModuleInfo module = ModuleController.Instance.GetModule(moduleID, Null.NullInteger, true);
var workflowStateController = new WorkflowStateController();
int workflowID = this.GetWorkflow(moduleID, module.TabID, module.PortalID).Value;
XmlNode xml = Globals.GetContent(content, "htmltext");

Expand All @@ -530,7 +526,7 @@ public void ImportModule(int moduleID, string content, string version, int userI
}

htmlContent.WorkflowID = workflowID;
htmlContent.StateID = workflowStateController.GetFirstWorkflowStateID(workflowID);
htmlContent.StateID = this.workflowManager.GetWorkflow(workflowID).FirstState.StateID;

// import
this.UpdateHtmlText(htmlContent, this.GetMaximumVersionHistory(module.PortalID));
Expand Down Expand Up @@ -633,6 +629,12 @@ private static List<string> CollectHierarchicalTags(List<Term> terms)
return collectTagsFunc(terms, new List<string>());
}

private static void TrackModuleModification(int moduleId, int moduleVersion)
{
var moduleInfo = ModuleController.Instance.GetModule(moduleId, Null.NullInteger, true);
TabChangeTracker.Instance.TrackModuleModification(moduleInfo, moduleVersion, UserController.Instance.GetCurrentUserInfo().UserID);
}

private void ClearModuleSettings(ModuleInfo objModule)
{
if (objModule.ModuleDefinition.FriendlyName == "Text/HTML")
Expand All @@ -656,7 +658,6 @@ private void CreateUserNotifications(HtmlTextInfo objHtmlText)
objHtmlText = this.GetHtmlText(objHtmlText.ModuleID, objHtmlText.ItemID);

// build collection of users to notify
var objWorkflow = new WorkflowStateController();
var arrUsers = new ArrayList();

// if not published
Expand All @@ -666,7 +667,7 @@ private void CreateUserNotifications(HtmlTextInfo objHtmlText)
}

// if not draft and not published
if (objHtmlText.StateID != objWorkflow.GetFirstWorkflowStateID(objHtmlText.WorkflowID) && objHtmlText.IsPublished == false)
if (objHtmlText.StateID != this.workflowManager.GetWorkflow(objHtmlText.WorkflowID).FirstState.StateID && objHtmlText.IsPublished == false)
{
// get users from permissions for state
foreach (WorkflowStatePermissionInfo permission in WorkflowStatePermissionController.GetWorkflowStatePermissions(objHtmlText.StateID))
Expand Down
Loading

0 comments on commit 08613ee

Please sign in to comment.