示例#1
0
            internal static void ModeratePage(string Action, Pages Page, PortalSettings PortalSettings)
            {
                UserInfo      UserInfo = PortalSettings.UserInfo;
                WorkflowState wState   = Page.StateID.HasValue ? WorkflowManager.GetStateByID(Page.StateID.Value) : null;
                bool          IsHaveReviewPermission = false;

                if (wState != null)
                {
                    IsHaveReviewPermission = WorkflowManager.HasReviewPermission(wState.StateID, UserInfo);
                }

                if (string.IsNullOrEmpty(Action) && !IsHaveReviewPermission)
                {
                    Page.StateID = WorkflowManager.GetFirstStateID(WorkflowManager.GetDefaultWorkflow(Page.TabID)).StateID;
                    AddLocalPages(Page, PortalSettings);
                }
                else if (!string.IsNullOrEmpty(Action) && Page.StateID.HasValue)
                {
                    foreach (string Locale in GetCultureListItems())
                    {
                        string _Locale = PortalSettings.DefaultLanguage == Locale ? null : Locale;

                        Pages LocalPage = GetLatestVersion(Page.TabID, _Locale, false);
                        if (LocalPage != null)
                        {
                            if (_Locale == Page.Locale)
                            {
                                LocalPage = Page;
                            }

                            if (Action == "approve" || Action == "publish")
                            {
                                int StateID = WorkflowManager.GetNextStateID(wState.WorkflowID, wState.StateID);
                                if (WorkflowManager.IsLastState(wState.WorkflowID, StateID))
                                {
                                    LocalPage.IsPublished = true;
                                    LocalPage.PublishedBy = UserInfo.UserID;
                                    LocalPage.PublishedOn = DateTime.UtcNow;
                                }
                                else
                                {
                                    LocalPage.IsPublished = false;
                                    LocalPage.PublishedBy = null;
                                    LocalPage.PublishedOn = null;
                                }
                                LocalPage.StateID = StateID;
                            }
                            else if (Action == "reject")
                            {
                                LocalPage.StateID = WorkflowManager.GetPreviousStateID(wState.WorkflowID, wState.StateID);
                            }

                            PageFactory.Update(LocalPage, UserInfo.UserID);
                        }
                    }
                }

                if (string.IsNullOrEmpty(Action) && IsHaveReviewPermission && !WorkflowManager.IsFirstState(wState.WorkflowID, wState.StateID))
                {
                    string      SystemLog = "System Log: Changes made by user";
                    WorkflowLog log       = WorkflowManager.GetPagesWorkflowLogs(Page.TabID, Page.Version).LastOrDefault();
                    if (log == null || (log != null && (!log.Comment.Contains(SystemLog) || log.ReviewedBy != UserInfo.UserID)))
                    {
                        WorkflowFactory.AddWorkflowLog(PortalSettings.PortalId, 0, UserInfo.UserID, Page, "approve", "System Log: Changes made by user");
                    }
                }

                PageFactory.Update(Page, UserInfo.UserID);
            }