From 08e6791ebf6c65ea85a199bb363baa79c7f885d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ton=C4=87i=20Vatavuk?= Date: Tue, 10 Dec 2024 16:50:21 +0100 Subject: [PATCH] Update HtmlText to Content Workflow API --- .../HTML/Components/HtmlTextController.cs | 131 ++++----- .../Components/WorkflowStateController.cs | 181 ------------- .../HTML/Components/WorkflowStateInfo.cs | 51 ---- .../HTML/DotNetNuke.Modules.Html.csproj | 3 +- ...DotNetNuke.Modules.Html.csproj.DotSettings | 2 + DNN Platform/Modules/HTML/EditHtml.ascx | 6 - DNN Platform/Modules/HTML/EditHtml.ascx.cs | 79 +++--- .../Modules/HTML/EditHtml.ascx.designer.cs | 254 +++++++++++++----- DNN Platform/Modules/HTML/HtmlModule.ascx.cs | 79 +----- .../SqlDataProvider/10.00.00.SqlDataProvider | 203 ++++++++++++++ DNN Platform/Modules/HTML/Settings.ascx.cs | 22 +- 11 files changed, 506 insertions(+), 505 deletions(-) delete mode 100644 DNN Platform/Modules/HTML/Components/WorkflowStateController.cs delete mode 100644 DNN Platform/Modules/HTML/Components/WorkflowStateInfo.cs create mode 100644 DNN Platform/Modules/HTML/DotNetNuke.Modules.Html.csproj.DotSettings create mode 100644 DNN Platform/Modules/HTML/Providers/DataProviders/SqlDataProvider/10.00.00.SqlDataProvider diff --git a/DNN Platform/Modules/HTML/Components/HtmlTextController.cs b/DNN Platform/Modules/HTML/Components/HtmlTextController.cs index e68bb6cf7b2..75d017c9e1b 100644 --- a/DNN Platform/Modules/HTML/Components/HtmlTextController.cs +++ b/DNN Platform/Modules/HTML/Components/HtmlTextController.cs @@ -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; @@ -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; @@ -35,12 +39,14 @@ namespace DotNetNuke.Modules.Html using Microsoft.Extensions.DependencyInjection; /// The HtmlTextController is the Controller class for managing HtmlText information the HtmlText module. - 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; + /// Initializes a new instance of the class. public HtmlTextController() : this(Globals.GetCurrentServiceProvider().GetRequiredService()) @@ -204,10 +210,14 @@ public string ReplaceWithRootToken(Match m) /// The ID of the Item. 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); } /// GetAllHtmlText gets a collection of HtmlTextInfo objects for the Module and Workflow. @@ -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)); @@ -267,61 +275,13 @@ public HtmlTextInfo GetTopHtmlText(int moduleId, bool isPublished, int workflowI /// A where the is the workflow type, and the is the workflow ID. public KeyValuePair 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(workFlowType, workFlowId); } @@ -331,7 +291,6 @@ public KeyValuePair GetWorkflow(int moduleId, int tabId, int portal /// The maximum number of versions to retain. 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 @@ -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; } @@ -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; } @@ -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; @@ -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); } /// UpdateWorkFlow updates the currently active Workflow. @@ -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(DataProvider.Instance().GetTopHtmlText(moduleId, true)); + return htmlText.Version; + } + + public int GetLatestVersion(int moduleId) + { + var htmlText = CBO.FillObject(DataProvider.Instance().GetTopHtmlText(moduleId, false)); + return htmlText.Version; + } + /// public string ExportModule(int moduleId) { @@ -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"); @@ -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)); @@ -633,6 +629,12 @@ private static List CollectHierarchicalTags(List terms) return collectTagsFunc(terms, new List()); } + 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") @@ -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 @@ -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)) diff --git a/DNN Platform/Modules/HTML/Components/WorkflowStateController.cs b/DNN Platform/Modules/HTML/Components/WorkflowStateController.cs deleted file mode 100644 index d0a95cb7eb8..00000000000 --- a/DNN Platform/Modules/HTML/Components/WorkflowStateController.cs +++ /dev/null @@ -1,181 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information -namespace DotNetNuke.Modules.Html -{ - using System.Collections; - using System.Web.Caching; - - using DotNetNuke.Common.Utilities; - using DotNetNuke.Modules.Html.Components; - - /// The WorkflowStateController is the Controller class for managing workflows and states for the HtmlText module. - public class WorkflowStateController - { - private const string WORKFLOWCACHEKEY = "Workflow{0}"; - private const string WORKFLOWSCACHEKEY = "Workflows{0}"; - private const int WORKFLOWCACHETIMEOUT = 20; - - private const CacheItemPriority WORKFLOWCACHEPRIORITY = CacheItemPriority.Normal; - - /// GetWorkFlows retrieves a collection of workflows for the portal from the cache. - /// The ID of the Portal. - /// An of instances. - public ArrayList GetWorkflows(int portalID) - { - var cacheKey = string.Format(WORKFLOWSCACHEKEY, portalID); - return CBO.GetCachedObject(new CacheItemArgs(cacheKey, WORKFLOWCACHETIMEOUT, WORKFLOWCACHEPRIORITY, portalID), this.GetWorkflowsCallBack); - } - - /// ----------------------------------------------------------------------------- - /// - /// GetWorkflowsCallBack retrieves a collection of WorkflowStateInfo objects for the Portal from the database. - /// - /// Arguments passed by the GetWorkflowStates method. - /// WorkflowStateInfo List. - /// ----------------------------------------------------------------------------- - public ArrayList GetWorkflowsCallBack(CacheItemArgs cacheItemArgs) - { - var portalId = (int)cacheItemArgs.ParamList[0]; - return CBO.FillCollection(DataProvider.Instance().GetWorkflows(portalId), typeof(WorkflowStateInfo)); - } - - /// GetWorkFlowStates retrieves a collection of WorkflowStateInfo objects for the Workflow from the cache. - /// The ID of the Workflow. - /// An of instances. - public ArrayList GetWorkflowStates(int workflowID) - { - string cacheKey = string.Format(WORKFLOWCACHEKEY, workflowID); - return CBO.GetCachedObject(new CacheItemArgs(cacheKey, WORKFLOWCACHETIMEOUT, WORKFLOWCACHEPRIORITY, workflowID), this.GetWorkflowStatesCallBack); - } - - /// GetWorkFlowStatesCallback retrieves a collection of WorkflowStateInfo objects for the Workflow from the database. - /// Arguments passed by the GetWorkflowStates method. - /// An of instances. - public object GetWorkflowStatesCallBack(CacheItemArgs cacheItemArgs) - { - var workflowID = (int)cacheItemArgs.ParamList[0]; - return CBO.FillCollection(DataProvider.Instance().GetWorkflowStates(workflowID), typeof(WorkflowStateInfo)); - } - - /// GetFirstWorkFlowStateID retrieves the first StateID for the Workflow. - /// The ID of the Workflow. - /// The workflow state ID or -1. - public int GetFirstWorkflowStateID(int workflowID) - { - int intStateID = -1; - ArrayList arrWorkflowStates = this.GetWorkflowStates(workflowID); - if (arrWorkflowStates.Count > 0) - { - intStateID = ((WorkflowStateInfo)arrWorkflowStates[0]).StateID; - } - - return intStateID; - } - - /// GetPreviousWorkFlowStateID retrieves the previous StateID for the Workflow and State specified. - /// The ID of the Workflow. - /// The ID of the State. - /// The previous workflow state ID (or the first workflow state ID if a previous state cannot be found). - public int GetPreviousWorkflowStateID(int workflowID, int stateID) - { - int intPreviousStateID = -1; - ArrayList arrWorkflowStates = this.GetWorkflowStates(workflowID); - int intItem = 0; - - // locate the current state - for (intItem = 0; intItem < arrWorkflowStates.Count; intItem++) - { - if (((WorkflowStateInfo)arrWorkflowStates[intItem]).StateID == stateID) - { - intPreviousStateID = stateID; - break; - } - } - - // get previous active state - if (intPreviousStateID == stateID) - { - intItem = intItem - 1; - while (intItem >= 0) - { - if (((WorkflowStateInfo)arrWorkflowStates[intItem]).IsActive) - { - intPreviousStateID = ((WorkflowStateInfo)arrWorkflowStates[intItem]).StateID; - break; - } - - intItem = intItem - 1; - } - } - - // if none found then reset to first state - if (intPreviousStateID == -1) - { - intPreviousStateID = this.GetFirstWorkflowStateID(workflowID); - } - - return intPreviousStateID; - } - - /// GetNextWorkFlowStateID retrieves the next StateID for the Workflow and State specified. - /// The ID of the Workflow. - /// The ID of the State. - /// The next workflow state ID (or the first workflow state ID if a next state cannot be found). - public int GetNextWorkflowStateID(int workflowID, int stateID) - { - int intNextStateID = -1; - ArrayList arrWorkflowStates = this.GetWorkflowStates(workflowID); - int intItem = 0; - - // locate the current state - for (intItem = 0; intItem < arrWorkflowStates.Count; intItem++) - { - if (((WorkflowStateInfo)arrWorkflowStates[intItem]).StateID == stateID) - { - intNextStateID = stateID; - break; - } - } - - // get next active state - if (intNextStateID == stateID) - { - intItem = intItem + 1; - while (intItem < arrWorkflowStates.Count) - { - if (((WorkflowStateInfo)arrWorkflowStates[intItem]).IsActive) - { - intNextStateID = ((WorkflowStateInfo)arrWorkflowStates[intItem]).StateID; - break; - } - - intItem = intItem + 1; - } - } - - // if none found then reset to first state - if (intNextStateID == -1) - { - intNextStateID = this.GetFirstWorkflowStateID(workflowID); - } - - return intNextStateID; - } - - /// GetLastWorkFlowStateID retrieves the last StateID for the Workflow. - /// The ID of the Workflow. - /// The workflow state ID or -1. - public int GetLastWorkflowStateID(int workflowID) - { - int intStateID = -1; - ArrayList arrWorkflowStates = this.GetWorkflowStates(workflowID); - if (arrWorkflowStates.Count > 0) - { - intStateID = ((WorkflowStateInfo)arrWorkflowStates[arrWorkflowStates.Count - 1]).StateID; - } - - return intStateID; - } - } -} diff --git a/DNN Platform/Modules/HTML/Components/WorkflowStateInfo.cs b/DNN Platform/Modules/HTML/Components/WorkflowStateInfo.cs deleted file mode 100644 index dac90507b9b..00000000000 --- a/DNN Platform/Modules/HTML/Components/WorkflowStateInfo.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information - -namespace DotNetNuke.Modules.Html -{ - using System; - - /// Namespace: DotNetNuke.Modules.Html - /// Project: DotNetNuke - /// Class: WorkflowStateInfo - /// Defines an instance of a WorkflowState object. - [Serializable] - public class WorkflowStateInfo - { - // local property declarations - private bool isActive = true; - - // public properties - public int PortalID { get; set; } - - public int WorkflowID { get; set; } - - public string WorkflowName { get; set; } - - public string Description { get; set; } - - public bool IsDeleted { get; set; } - - public int StateID { get; set; } - - public string StateName { get; set; } - - public int Order { get; set; } - - public bool Notify { get; set; } - - public bool IsActive - { - get - { - return this.isActive; - } - - set - { - this.isActive = value; - } - } - } -} diff --git a/DNN Platform/Modules/HTML/DotNetNuke.Modules.Html.csproj b/DNN Platform/Modules/HTML/DotNetNuke.Modules.Html.csproj index a3bb07dea41..36992033395 100644 --- a/DNN Platform/Modules/HTML/DotNetNuke.Modules.Html.csproj +++ b/DNN Platform/Modules/HTML/DotNetNuke.Modules.Html.csproj @@ -143,8 +143,6 @@ - - @@ -222,6 +220,7 @@ + diff --git a/DNN Platform/Modules/HTML/DotNetNuke.Modules.Html.csproj.DotSettings b/DNN Platform/Modules/HTML/DotNetNuke.Modules.Html.csproj.DotSettings new file mode 100644 index 00000000000..0e84b0ca44b --- /dev/null +++ b/DNN Platform/Modules/HTML/DotNetNuke.Modules.Html.csproj.DotSettings @@ -0,0 +1,2 @@ + + True \ No newline at end of file diff --git a/DNN Platform/Modules/HTML/EditHtml.ascx b/DNN Platform/Modules/HTML/EditHtml.ascx index 5c2f5fdc8a1..48b3c41fd62 100644 --- a/DNN Platform/Modules/HTML/EditHtml.ascx +++ b/DNN Platform/Modules/HTML/EditHtml.ascx @@ -28,17 +28,11 @@ -
( ) ( )
-
- - -
-
diff --git a/DNN Platform/Modules/HTML/EditHtml.ascx.cs b/DNN Platform/Modules/HTML/EditHtml.ascx.cs index ff1cfb96e1e..e7b230f1681 100644 --- a/DNN Platform/Modules/HTML/EditHtml.ascx.cs +++ b/DNN Platform/Modules/HTML/EditHtml.ascx.cs @@ -11,8 +11,12 @@ namespace DotNetNuke.Modules.Html using DotNetNuke.Abstractions; using DotNetNuke.Common.Utilities; + using DotNetNuke.Entities.Content.Workflow; + using DotNetNuke.Entities.Content.Workflow.Entities; using DotNetNuke.Entities.Modules; using DotNetNuke.Entities.Portals; + using DotNetNuke.Entities.Tabs; + using DotNetNuke.Entities.Tabs.TabVersions; using DotNetNuke.Entities.Users; using DotNetNuke.Modules.Html.Components; using DotNetNuke.Security; @@ -26,10 +30,9 @@ namespace DotNetNuke.Modules.Html public partial class EditHtml : HtmlModuleBase { private readonly INavigationManager navigationManager; - private readonly HtmlTextController htmlTextController; private readonly HtmlTextLogController htmlTextLogController = new HtmlTextLogController(); - private readonly WorkflowStateController workflowStateController = new WorkflowStateController(); + private readonly IWorkflowManager workflowManager = WorkflowManager.Instance; public EditHtml() { @@ -40,7 +43,8 @@ public EditHtml() private enum WorkflowType { DirectPublish = 1, - ContentStaging = 2, + SaveDraft = 2, + ContentApproval = 3, } protected string CurrentView @@ -125,6 +129,10 @@ private WorkflowType CurrentWorkflowType } } + private bool IsVersioningEnabled => TabVersionSettings.Instance.IsVersioningEnabled(PortalSettings.Current.PortalId, TabController.CurrentPage.TabID); + + private bool IsWorkflowEnabled => this.IsVersioningEnabled && TabWorkflowSettings.Instance.IsWorkflowEnabled(PortalSettings.Current.PortalId, TabController.CurrentPage.TabID); + /// protected override void OnInit(EventArgs e) { @@ -151,7 +159,7 @@ protected override void OnLoad(EventArgs e) try { - var htmlContentItemID = -1; + var htmlContentItemID = Null.NullInteger; var htmlContent = this.htmlTextController.GetTopHtmlText(this.ModuleId, false, this.WorkflowID); if (htmlContent != null) @@ -161,20 +169,24 @@ protected override void OnLoad(EventArgs e) if (!this.Page.IsPostBack) { - var workflowStates = this.workflowStateController.GetWorkflowStates(this.WorkflowID); + var workflow = this.workflowManager.GetWorkflow(this.WorkflowID); + var workflowStates = workflow.States.ToList(); var maxVersions = this.htmlTextController.GetMaximumVersionHistory(this.PortalId); var userCanEdit = this.UserInfo.IsSuperUser || PortalSecurity.IsInRole(this.PortalSettings.AdministratorRoleName); this.lblMaxVersions.Text = maxVersions.ToString(); this.dgVersions.PageSize = Math.Min(Math.Max(maxVersions, 5), 10); // min 5, max 10 - switch (workflowStates.Count) + switch (workflow.WorkflowKey) { - case 1: + case SystemWorkflowManager.DirectPublishWorkflowKey: this.CurrentWorkflowType = WorkflowType.DirectPublish; break; - case 2: - this.CurrentWorkflowType = WorkflowType.ContentStaging; + case SystemWorkflowManager.SaveDraftWorkflowKey: + this.CurrentWorkflowType = WorkflowType.SaveDraft; + break; + case SystemWorkflowManager.ContentAprovalWorkflowKey: + this.CurrentWorkflowType = WorkflowType.ContentApproval; break; } @@ -187,10 +199,9 @@ protected override void OnLoad(EventArgs e) } else { - this.DisplayInitialContent(workflowStates[0] as WorkflowStateInfo); + this.DisplayInitialContent(workflowStates[0]); } - this.divPublish.Visible = this.CurrentWorkflowType != WorkflowType.DirectPublish; this.phCurrentVersion.Visible = this.CurrentWorkflowType != WorkflowType.DirectPublish; this.phPreviewVersion.Visible = this.CurrentWorkflowType != WorkflowType.DirectPublish; @@ -232,9 +243,9 @@ protected void OnSaveClick(object sender, EventArgs e) } htmlContent.Content = content; - - var draftStateID = this.workflowStateController.GetFirstWorkflowStateID(this.WorkflowID); - var publishedStateID = this.workflowStateController.GetLastWorkflowStateID(this.WorkflowID); + var workflow = this.workflowManager.GetWorkflow(this.WorkflowID); + var draftStateID = workflow.FirstState.StateID; + var publishedStateID = workflow.LastState.StateID; switch (this.CurrentWorkflowType) { @@ -242,28 +253,12 @@ protected void OnSaveClick(object sender, EventArgs e) this.htmlTextController.UpdateHtmlText(htmlContent, this.htmlTextController.GetMaximumVersionHistory(this.PortalId)); break; - case WorkflowType.ContentStaging: - if (this.chkPublish.Checked) + case WorkflowType.SaveDraft: + case WorkflowType.ContentApproval: + // if it's already published set it back to draft + if (htmlContent.StateID == publishedStateID) { - // if it's already published set it to draft - if (htmlContent.StateID == publishedStateID) - { - htmlContent.StateID = draftStateID; - } - else - { - htmlContent.StateID = publishedStateID; - - // here it's in published mode - } - } - else - { - // if it's already published set it back to draft - if (htmlContent.StateID != draftStateID) - { - htmlContent.StateID = draftStateID; - } + htmlContent.StateID = draftStateID; } this.htmlTextController.UpdateHtmlText(htmlContent, this.htmlTextController.GetMaximumVersionHistory(this.PortalId)); @@ -348,7 +343,7 @@ protected void OnVersionsGridItemCommand(object source, GridViewCommandEventArgs htmlContent.ItemID = -1; htmlContent.ModuleID = this.ModuleId; htmlContent.WorkflowID = this.WorkflowID; - htmlContent.StateID = this.workflowStateController.GetFirstWorkflowStateID(this.WorkflowID); + htmlContent.StateID = this.workflowManager.GetWorkflow(this.WorkflowID).FirstState.StateID; this.htmlTextController.UpdateHtmlText(htmlContent, this.htmlTextController.GetMaximumVersionHistory(this.PortalId)); break; case "preview": @@ -362,7 +357,7 @@ protected void OnVersionsGridItemCommand(object source, GridViewCommandEventArgs var latestContent = this.htmlTextController.GetTopHtmlText(this.ModuleId, false, this.WorkflowID); if (latestContent == null) { - this.DisplayInitialContent(this.workflowStateController.GetWorkflowStates(this.WorkflowID)[0] as WorkflowStateInfo); + this.DisplayInitialContent(this.workflowManager.GetWorkflow(this.WorkflowID).FirstState); } else { @@ -604,8 +599,6 @@ private void DisplayLockedContent(HtmlTextInfo htmlContent, HtmlTextInfo lastPub this.cmdSave.Visible = false; // cmdPreview.Enabled = false; - this.divPublish.Visible = false; - this.divSubmittedContent.Visible = true; this.lblCurrentWorkflowInUse.Text = this.GetLocalizedString(htmlContent.WorkflowName); @@ -631,14 +624,14 @@ private void DisplayLockedContent(HtmlTextInfo htmlContent, HtmlTextInfo lastPub /// Displays the initial content when a module is first added to the page. /// The first state. - private void DisplayInitialContent(WorkflowStateInfo firstState) + private void DisplayInitialContent(WorkflowState firstState) { this.cmdHistory.Enabled = false; this.txtContent.Text = this.GetLocalizedString("AddContent"); this.litPreview.Text = this.GetLocalizedString("AddContent"); - this.lblCurrentWorkflowInUse.Text = firstState.WorkflowName; - this.lblPreviewWorkflowInUse.Text = firstState.WorkflowName; + this.lblCurrentWorkflowInUse.Text = this.workflowManager.GetWorkflow(firstState.WorkflowID).WorkflowName; + this.lblPreviewWorkflowInUse.Text = this.workflowManager.GetWorkflow(firstState.WorkflowID).WorkflowName; this.divPreviewVersion.Visible = false; this.dnnSitePanelEditHTMLHistory.Visible = false; @@ -680,7 +673,7 @@ private HtmlTextInfo GetLatestHTMLContent() { htmlContent = new HtmlTextInfo(); htmlContent.ItemID = -1; - htmlContent.StateID = this.workflowStateController.GetFirstWorkflowStateID(this.WorkflowID); + htmlContent.StateID = this.workflowManager.GetWorkflow(this.WorkflowID).FirstState.StateID; htmlContent.WorkflowID = this.WorkflowID; htmlContent.ModuleID = this.ModuleId; } diff --git a/DNN Platform/Modules/HTML/EditHtml.ascx.designer.cs b/DNN Platform/Modules/HTML/EditHtml.ascx.designer.cs index ed0db1207f7..5a3bfcab16b 100644 --- a/DNN Platform/Modules/HTML/EditHtml.ascx.designer.cs +++ b/DNN Platform/Modules/HTML/EditHtml.ascx.designer.cs @@ -1,8 +1,4 @@ -// -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the MIT License. See LICENSE file in the project root for full license information. -// -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by a tool. // @@ -11,287 +7,403 @@ // //------------------------------------------------------------------------------ -namespace DotNetNuke.Modules.Html { - - - public partial class EditHtml { - /// customJS control. +namespace DotNetNuke.Modules.Html +{ + + + public partial class EditHtml + { + + /// + /// customJS control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::DotNetNuke.Web.Client.ClientResourceManagement.DnnCssInclude customJS; - /// phEdit control. + + /// + /// phEdit control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.PlaceHolder phEdit; - /// phMasterContent control. + + /// + /// phMasterContent control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.PlaceHolder phMasterContent; - /// ehmContent control. + + /// + /// ehmContent control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.HtmlControls.HtmlGenericControl ehmContent; - /// placeMasterContent control. + + /// + /// placeMasterContent control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.PlaceHolder placeMasterContent; - /// txtContent control. + + /// + /// txtContent control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::DotNetNuke.UI.UserControls.TextEditor txtContent; - /// divSubmittedContent control. + + /// + /// divSubmittedContent control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.HtmlControls.HtmlGenericControl divSubmittedContent; - /// Div3 control. + + /// + /// Div3 control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.HtmlControls.HtmlGenericControl Div3; - /// litCurrentContentPreview control. + + /// + /// litCurrentContentPreview control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.Literal litCurrentContentPreview; - /// phCurrentVersion control. + + /// + /// phCurrentVersion control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.PlaceHolder phCurrentVersion; - /// divCurrentWorkflowState control. + + /// + /// divCurrentWorkflowState control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.HtmlControls.HtmlGenericControl divCurrentWorkflowState; - /// plCurrentWorkflowState control. + + /// + /// plCurrentWorkflowState control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.UserControl plCurrentWorkflowState; - /// lblCurrentWorkflowState control. + + /// + /// lblCurrentWorkflowState control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.Label lblCurrentWorkflowState; - /// plCurrentWorkVersion control. + + /// + /// plCurrentWorkVersion control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.Label plCurrentWorkVersion; - /// lblCurrentVersion control. + + /// + /// lblCurrentVersion control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.Label lblCurrentVersion; - /// lblCurrentWorkflowInUse control. + + /// + /// lblCurrentWorkflowInUse control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.Label lblCurrentWorkflowInUse; - /// divPublish control. - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.HtmlControls.HtmlGenericControl divPublish; - /// plActionOnSave control. - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.UserControl plActionOnSave; - /// chkPublish control. - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.CheckBox chkPublish; - /// phPreview control. + + /// + /// phPreview control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.PlaceHolder phPreview; - /// phPreviewVersion control. + + /// + /// phPreviewVersion control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.PlaceHolder phPreviewVersion; - /// divPreviewVersion control. + + /// + /// divPreviewVersion control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.HtmlControls.HtmlGenericControl divPreviewVersion; - /// plPreviewVersion control. + + /// + /// plPreviewVersion control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.UserControl plPreviewVersion; - /// lblPreviewVersion control. + + /// + /// lblPreviewVersion control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.Label lblPreviewVersion; - /// divPreviewWorlflow control. + + /// + /// divPreviewWorlflow control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.HtmlControls.HtmlGenericControl divPreviewWorlflow; - /// plPreviewWorkflowInUse control. + + /// + /// plPreviewWorkflowInUse control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.UserControl plPreviewWorkflowInUse; - /// lblPreviewWorkflowInUse control. + + /// + /// lblPreviewWorkflowInUse control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.Label lblPreviewWorkflowInUse; - /// divPreviewWorkflowState control. + + /// + /// divPreviewWorkflowState control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.HtmlControls.HtmlGenericControl divPreviewWorkflowState; - /// plPreviewWorkflowState control. + + /// + /// plPreviewWorkflowState control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.UserControl plPreviewWorkflowState; - /// lblPreviewWorkflowState control. + + /// + /// lblPreviewWorkflowState control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.Label lblPreviewWorkflowState; - /// Div1 control. + + /// + /// Div1 control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.HtmlControls.HtmlGenericControl Div1; - /// litPreview control. + + /// + /// litPreview control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.Literal litPreview; - /// dnnSitePanelEditHTMLHistory control. + + /// + /// dnnSitePanelEditHTMLHistory control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.HtmlControls.HtmlGenericControl dnnSitePanelEditHTMLHistory; - /// fsEditHtmlHistory control. + + /// + /// fsEditHtmlHistory control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.HtmlControls.HtmlGenericControl fsEditHtmlHistory; - /// dgHistory control. + + /// + /// dgHistory control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::DotNetNuke.Web.UI.WebControls.Internal.DnnGrid dgHistory; - /// phHistory control. + + /// + /// phHistory control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.PlaceHolder phHistory; - /// plMaxVersions control. + + /// + /// plMaxVersions control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.UserControl plMaxVersions; - /// lblMaxVersions control. + + /// + /// lblMaxVersions control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.Label lblMaxVersions; - /// dgVersions control. + + /// + /// dgVersions control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::DotNetNuke.Web.UI.WebControls.Internal.DnnGrid dgVersions; - /// cmdSave control. + + /// + /// cmdSave control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.LinkButton cmdSave; - /// hlCancel control. + + /// + /// hlCancel control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.HyperLink hlCancel; - /// cmdEdit control. + + /// + /// cmdEdit control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.LinkButton cmdEdit; - /// cmdPreview control. + + /// + /// cmdPreview control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.LinkButton cmdPreview; - /// cmdHistory control. + + /// + /// cmdHistory control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.LinkButton cmdHistory; - /// ddlRender control. + + /// + /// ddlRender control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.DropDownList ddlRender; - /// cmdMasterContent control. + + /// + /// cmdMasterContent control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.LinkButton cmdMasterContent; - /// hfEditor control. + + /// + /// hfEditor control. + /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. diff --git a/DNN Platform/Modules/HTML/HtmlModule.ascx.cs b/DNN Platform/Modules/HTML/HtmlModule.ascx.cs index 1e303f27025..e7405c9a566 100644 --- a/DNN Platform/Modules/HTML/HtmlModule.ascx.cs +++ b/DNN Platform/Modules/HTML/HtmlModule.ascx.cs @@ -4,10 +4,12 @@ namespace DotNetNuke.Modules.Html { using System; + using System.Linq; using System.Web.UI; using DotNetNuke.Abstractions; using DotNetNuke.Common; + using DotNetNuke.Entities.Content.Workflow; using DotNetNuke.Entities.Modules; using DotNetNuke.Entities.Modules.Actions; using DotNetNuke.Entities.Portals; @@ -24,7 +26,8 @@ namespace DotNetNuke.Modules.Html /// The HtmlModule Class provides the UI for displaying the Html. public partial class HtmlModule : HtmlModuleBase, IActionable { - private readonly INavigationManager navigationManager; + private readonly INavigationManager navigationManager; + private readonly IWorkflowManager workflowManager = WorkflowManager.Instance; private bool editorEnabled; private int workflowID; @@ -53,70 +56,6 @@ public ModuleActionCollection ModuleActions true, false); - // get the content - var objHTML = new HtmlTextController(this.navigationManager); - var objWorkflow = new WorkflowStateController(); - this.workflowID = objHTML.GetWorkflow(this.ModuleId, this.TabId, this.PortalId).Value; - - HtmlTextInfo objContent = objHTML.GetTopHtmlText(this.ModuleId, false, this.workflowID); - if (objContent != null) - { - // if content is in the first state - if (objContent.StateID == objWorkflow.GetFirstWorkflowStateID(this.workflowID)) - { - // if not direct publish workflow - if (objWorkflow.GetWorkflowStates(this.workflowID).Count > 1) - { - // add publish action - actions.Add( - this.GetNextActionID(), - Localization.GetString("PublishContent.Action", this.LocalResourceFile), - ModuleActionType.AddContent, - "publish", - "grant.gif", - string.Empty, - true, - SecurityAccessLevel.Edit, - true, - false); - } - } - else - { - // if the content is not in the last state of the workflow then review is required - if (objContent.StateID != objWorkflow.GetLastWorkflowStateID(this.workflowID)) - { - // if the user has permissions to review the content - if (WorkflowStatePermissionController.HasWorkflowStatePermission(WorkflowStatePermissionController.GetWorkflowStatePermissions(objContent.StateID), "REVIEW")) - { - // add approve and reject actions - actions.Add( - this.GetNextActionID(), - Localization.GetString("ApproveContent.Action", this.LocalResourceFile), - ModuleActionType.AddContent, - string.Empty, - "grant.gif", - this.EditUrl("action", "approve", "Review"), - false, - SecurityAccessLevel.Edit, - true, - false); - actions.Add( - this.GetNextActionID(), - Localization.GetString("RejectContent.Action", this.LocalResourceFile), - ModuleActionType.AddContent, - string.Empty, - "deny.gif", - this.EditUrl("action", "reject", "Review"), - false, - SecurityAccessLevel.Edit, - true, - false); - } - } - } - } - // add mywork to action menu actions.Add( this.GetNextActionID(), @@ -262,7 +201,6 @@ private void LblContent_UpdateLabel(object source, DNNLabelEditEventArgs e) { // get content var objHTML = new HtmlTextController(this.navigationManager); - var objWorkflow = new WorkflowStateController(); HtmlTextInfo objContent = objHTML.GetTopHtmlText(this.ModuleId, false, this.workflowID); if (objContent == null) { @@ -274,7 +212,7 @@ private void LblContent_UpdateLabel(object source, DNNLabelEditEventArgs e) objContent.ModuleID = this.ModuleId; objContent.Content = this.Server.HtmlEncode(e.Text); objContent.WorkflowID = this.workflowID; - objContent.StateID = objWorkflow.GetFirstWorkflowStateID(this.workflowID); + objContent.StateID = this.workflowManager.GetWorkflow(this.workflowID).FirstState.StateID; // save the content objHTML.UpdateHtmlText(objContent, objHTML.GetMaximumVersionHistory(this.PortalId)); @@ -303,12 +241,11 @@ private void ModuleAction_Click(object sender, ActionEventArgs e) // get content var objHTML = new HtmlTextController(this.navigationManager); HtmlTextInfo objContent = objHTML.GetTopHtmlText(this.ModuleId, false, this.workflowID); - - var objWorkflow = new WorkflowStateController(); - if (objContent.StateID == objWorkflow.GetFirstWorkflowStateID(this.workflowID)) + var workflow = this.workflowManager.GetWorkflow(this.workflowID); + if (objContent.StateID == workflow.FirstState.StateID) { // publish content - objContent.StateID = objWorkflow.GetNextWorkflowStateID(objContent.WorkflowID, objContent.StateID); + objContent.StateID = workflow.LastState.StateID; // save the content objHTML.UpdateHtmlText(objContent, objHTML.GetMaximumVersionHistory(this.PortalId)); diff --git a/DNN Platform/Modules/HTML/Providers/DataProviders/SqlDataProvider/10.00.00.SqlDataProvider b/DNN Platform/Modules/HTML/Providers/DataProviders/SqlDataProvider/10.00.00.SqlDataProvider new file mode 100644 index 00000000000..6a7a727e611 --- /dev/null +++ b/DNN Platform/Modules/HTML/Providers/DataProviders/SqlDataProvider/10.00.00.SqlDataProvider @@ -0,0 +1,203 @@ +/************************************************************/ +/***** SqlDataProvider *****/ +/***** *****/ +/***** *****/ +/***** Note: To manually execute this script you must *****/ +/***** perform a search and replace operation *****/ +/***** for {databaseOwner} and {objectQualifier} *****/ +/***** *****/ +/************************************************************/ + + +/************************************************************/ +/***** SqlDataProvider *****/ +/************************************************************/ + +-- Drop Foreign Key FK_HtmlText_WorkflowStates if it exists +IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'{databaseOwner}{objectQualifier}FK_HtmlText_WorkflowStates') AND parent_object_id = OBJECT_ID(N'{databaseOwner}{objectQualifier}HtmlText')) + BEGIN + ALTER TABLE {databaseOwner}{objectQualifier}HtmlText DROP CONSTRAINT FK_HtmlText_WorkflowStates; + END +GO + +-- Drop Foreign Key FK_HtmlTextLog_WorkflowStates if it exists +IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'{databaseOwner}{objectQualifier}FK_HtmlTextLog_WorkflowStates') AND parent_object_id = OBJECT_ID(N'{databaseOwner}{objectQualifier}HtmlTextLog')) + BEGIN + ALTER TABLE {databaseOwner}{objectQualifier}HtmlTextLog DROP CONSTRAINT FK_HtmlTextLog_WorkflowStates; + END +GO + +-- Drop Foreign Key FK_WorkflowStates_Workflow if it exists +IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'{databaseOwner}{objectQualifier}FK_WorkflowStates_Workflow') AND parent_object_id = OBJECT_ID(N'{databaseOwner}{objectQualifier}WorkflowStates')) + BEGIN + ALTER TABLE {databaseOwner}{objectQualifier}WorkflowStates DROP CONSTRAINT FK_WorkflowStates_Workflow; + END +GO + +-- Drop Table Workflow if it exists +IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{databaseOwner}{objectQualifier}Workflow') AND type in (N'U')) + BEGIN + DROP TABLE {databaseOwner}{objectQualifier}Workflow; + END +GO + +-- Drop Table WorkflowStates if it exists +IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{databaseOwner}{objectQualifier}WorkflowStates') AND type in (N'U')) + BEGIN + DROP TABLE {databaseOwner}{objectQualifier}WorkflowStates; + END +GO + +-- Create Foreign Key FK_HtmlText_WorkflowStates if it does not exist +IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'{databaseOwner}{objectQualifier}FK_HtmlText_WorkflowStates') AND parent_object_id = OBJECT_ID(N'{databaseOwner}{objectQualifier}HtmlText')) + BEGIN + ALTER TABLE {databaseOwner}{objectQualifier}HtmlText WITH NOCHECK + ADD CONSTRAINT FK_HtmlText_WorkflowStates FOREIGN KEY (StateID) REFERENCES {databaseOwner}{objectQualifier}ContentWorkflowStates (StateID); + END +GO + +-- Create Foreign Key FK_HtmlTextLog_WorkflowStates if it does not exist +IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'{databaseOwner}{objectQualifier}FK_HtmlTextLog_WorkflowStates') AND parent_object_id = OBJECT_ID(N'{databaseOwner}{objectQualifier}HtmlTextLog')) + BEGIN + ALTER TABLE {databaseOwner}{objectQualifier}HtmlTextLog WITH NOCHECK + ADD CONSTRAINT FK_HtmlTextLog_WorkflowStates FOREIGN KEY (StateID) REFERENCES {databaseOwner}{objectQualifier}ContentWorkflowStates (StateID); + END +GO + +-- Drop Procedure GetAllHtmlText if it exists +IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{databaseOwner}{objectQualifier}GetAllHtmlText') AND type in (N'P', N'PC')) + BEGIN + DROP PROCEDURE {databaseOwner}{objectQualifier}GetAllHtmlText; + END +GO + +-- Create Procedure GetAllHtmlText +CREATE PROCEDURE {databaseOwner}{objectQualifier}GetAllHtmlText + @ModuleID INT +AS +BEGIN + SELECT dbo.HtmlText.*, + dbo.ContentWorkflowStates.*, + dbo.ContentWorkflows.WorkflowName, + dbo.Users.DisplayName, + dbo.Modules.PortalID + FROM dbo.HtmlText + INNER JOIN dbo.Modules ON dbo.Modules.ModuleID = dbo.HtmlText.ModuleID + INNER JOIN dbo.ContentWorkflowStates ON dbo.ContentWorkflowStates.StateID = dbo.HtmlText.StateID + INNER JOIN dbo.ContentWorkflows ON dbo.ContentWorkflowStates.WorkflowID = dbo.ContentWorkflows.WorkflowID + LEFT OUTER JOIN dbo.Users ON dbo.HtmlText.LastModifiedByUserID = dbo.Users.UserID + WHERE dbo.HtmlText.ModuleID = @ModuleID + ORDER BY dbo.HtmlText.LastModifiedOnDate DESC +END +GO + +-- Drop Procedure GetHtmlText if it exists +IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{databaseOwner}{objectQualifier}GetHtmlText') AND type in (N'P', N'PC')) + BEGIN + DROP PROCEDURE {databaseOwner}{objectQualifier}GetHtmlText; + END +GO + +-- Create Procedure GetHtmlText +CREATE PROCEDURE {databaseOwner}{objectQualifier}GetHtmlText + @ModuleID INT, + @ItemID INT +AS +BEGIN + SELECT dbo.HtmlText.*, + dbo.ContentWorkflowStates.*, + dbo.ContentWorkflows.WorkflowName, + dbo.Users.DisplayName, + dbo.Modules.PortalID + FROM dbo.HtmlText + INNER JOIN dbo.Modules ON dbo.Modules.ModuleID = dbo.HtmlText.ModuleID + INNER JOIN dbo.ContentWorkflowStates ON dbo.ContentWorkflowStates.StateID = dbo.HtmlText.StateID + INNER JOIN dbo.ContentWorkflows ON dbo.ContentWorkflowStates.WorkflowID = dbo.ContentWorkflows.WorkflowID + LEFT OUTER JOIN dbo.Users ON dbo.HtmlText.LastModifiedByUserID = dbo.Users.UserID + WHERE dbo.HtmlText.ModuleID = @ModuleID + AND ItemID = @ItemID +END +GO + +-- Drop Procedure GetHtmlTextLog if it exists +IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{databaseOwner}{objectQualifier}GetHtmlTextLog') AND type in (N'P', N'PC')) + BEGIN + DROP PROCEDURE {databaseOwner}{objectQualifier}GetHtmlTextLog; + END +GO + +-- Create Procedure GetHtmlTextLog +CREATE PROCEDURE {databaseOwner}{objectQualifier}GetHtmlTextLog + @ItemID INT +AS +BEGIN + SELECT HtmlTextLog.ItemID, + HtmlTextLog.StateID, + ContentWorkflowStates.StateName, + HtmlTextLog.Comment, + HtmlTextLog.Approved, + HtmlTextLog.CreatedByUserID, + Users.DisplayName, + HtmlTextLog.CreatedOnDate + FROM dbo.HtmlTextLog + INNER JOIN dbo.ContentWorkflowStates ON dbo.HtmlTextLog.StateID = dbo.ContentWorkflowStates.StateID + LEFT OUTER JOIN dbo.Users ON dbo.HtmlTextLog.CreatedByUserID = dbo.Users.UserID + WHERE ItemID = @ItemID + ORDER BY HtmlTextLog.CreatedOnDate DESC +END +GO + +-- Drop Procedure GetHtmlTextUser if it exists +IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{databaseOwner}{objectQualifier}GetHtmlTextUser') AND type in (N'P', N'PC')) + BEGIN + DROP PROCEDURE {databaseOwner}{objectQualifier}GetHtmlTextUser; + END +GO + +-- Create Procedure GetHtmlTextUser +CREATE PROCEDURE {databaseOwner}{objectQualifier}GetHtmlTextUser + @UserID INT +AS +BEGIN + SELECT HtmlTextUsers.*, + ContentWorkflowStates.StateName + FROM dbo.HtmlTextUsers + INNER JOIN dbo.ContentWorkflowStates ON dbo.HtmlTextUsers.StateID = dbo.ContentWorkflowStates.StateID + WHERE HtmlTextUsers.UserID = @UserID + ORDER BY HtmlTextUsers.CreatedOnDate ASC +END +GO + +-- Drop Procedure GetTopHtmlText if it exists +IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{databaseOwner}{objectQualifier}GetTopHtmlText') AND type in (N'P', N'PC')) + BEGIN + DROP PROCEDURE {databaseOwner}{objectQualifier}GetTopHtmlText; + END +GO + +-- Create Procedure GetTopHtmlText +CREATE PROCEDURE {databaseOwner}{objectQualifier}GetTopHtmlText + @ModuleID INT, + @IsPublished BIT +AS +BEGIN + SELECT TOP 1 dbo.HtmlText.*, + dbo.ContentWorkflowStates.*, + dbo.ContentWorkflows.WorkflowName, + dbo.Users.DisplayName, + dbo.Modules.PortalID + FROM dbo.HtmlText + INNER JOIN dbo.Modules ON dbo.Modules.ModuleID = dbo.HtmlText.ModuleID + INNER JOIN dbo.ContentWorkflowStates ON dbo.ContentWorkflowStates.StateID = dbo.HtmlText.StateID + INNER JOIN dbo.ContentWorkflows ON dbo.ContentWorkflowStates.WorkflowID = dbo.ContentWorkflows.WorkflowID + LEFT OUTER JOIN dbo.Users ON dbo.HtmlText.LastModifiedByUserID = dbo.Users.UserID + WHERE dbo.HtmlText.ModuleID = @ModuleID + AND (IsPublished = @IsPublished OR @IsPublished = 0) + ORDER BY dbo.HtmlText.LastModifiedOnDate DESC +END +GO + +-- Enable constraints after checking existing data +ALTER TABLE {databaseOwner}{objectQualifier}HtmlText WITH CHECK CHECK CONSTRAINT FK_HtmlText_WorkflowStates; +ALTER TABLE {databaseOwner}{objectQualifier}HtmlTextLog WITH CHECK CHECK CONSTRAINT FK_HtmlTextLog_WorkflowStates; +GO diff --git a/DNN Platform/Modules/HTML/Settings.ascx.cs b/DNN Platform/Modules/HTML/Settings.ascx.cs index 0ab0742850e..9a8e788e5a7 100644 --- a/DNN Platform/Modules/HTML/Settings.ascx.cs +++ b/DNN Platform/Modules/HTML/Settings.ascx.cs @@ -6,8 +6,11 @@ namespace DotNetNuke.Modules.Html using System; using System.Collections; using System.Collections.Generic; + using System.Linq; using DotNetNuke.Abstractions; + using DotNetNuke.Entities.Content.Workflow; + using DotNetNuke.Entities.Content.Workflow.Entities; using DotNetNuke.Entities.Modules; using DotNetNuke.Modules.Html.Components; using DotNetNuke.Services.Exceptions; @@ -21,6 +24,7 @@ namespace DotNetNuke.Modules.Html public partial class Settings : ModuleSettingsBase { private readonly INavigationManager navigationManager; + private readonly IWorkflowManager workflowManager = WorkflowManager.Instance; private HtmlModuleSettings moduleSettings; @@ -46,21 +50,12 @@ public override void LoadSettings() if (!this.Page.IsPostBack) { var htmlTextController = new HtmlTextController(this.navigationManager); - var workflowStateController = new WorkflowStateController(); this.chkReplaceTokens.Checked = this.ModuleSettings.ReplaceTokens; this.cbDecorate.Checked = this.ModuleSettings.UseDecorate; // get workflow/version settings - var workflows = new ArrayList(); - foreach (WorkflowStateInfo state in workflowStateController.GetWorkflows(this.PortalId)) - { - if (!state.IsDeleted) - { - workflows.Add(state); - } - } - + var workflows = this.workflowManager.GetWorkflows(this.PortalId); this.cboWorkflow.DataSource = workflows; this.cboWorkflow.DataBind(); var workflow = htmlTextController.GetWorkflow(this.ModuleId, this.TabId, this.PortalId); @@ -150,17 +145,14 @@ private void DisplayWorkflowDetails() { if (this.cboWorkflow.SelectedValue != null) { - var objWorkflow = new WorkflowStateController(); var strDescription = string.Empty; - var arrStates = objWorkflow.GetWorkflowStates(int.Parse(this.cboWorkflow.SelectedValue)); + var arrStates = this.workflowManager.GetWorkflow(int.Parse(this.cboWorkflow.SelectedValue)).States.ToList(); if (arrStates.Count > 0) { - foreach (WorkflowStateInfo objState in arrStates) + foreach (var objState in arrStates) { strDescription = strDescription + " >> " + "" + objState.StateName + ""; } - - strDescription = strDescription + "
" + ((WorkflowStateInfo)arrStates[0]).Description; } this.lblDescription.Text = strDescription;