Ejemplo n.º 1
0
    /// <summary>
    /// Archive event handler.
    /// </summary>
    protected void btnArchive_Click(object sender, EventArgs e)
    {
        // Check modify permissions
        if (CMSContext.CurrentUser.IsAuthorizedPerDocument(Node, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied)
        {
            return;
        }

        // Get original step
        WorkflowStepInfo originalStep = WorkflowManager.GetStepInfo(Node);

        // Archive document
        WorkflowStepInfo nextStep = WorkflowManager.ArchiveDocument(Node, txtComment.Text);

        currentStepId = nextStep.StepID;

        // Send workflow e-mails
        if (chkSendMail.Checked && SendWorkflowEmails)
        {
            WorkflowManager.SendWorkflowEmails(Node, CMSContext.CurrentUser, originalStep, nextStep, WorkflowActionEnum.Archived, txtComment.Text);
        }

        ClearComment();

        string siteName = CMSContext.CurrentSiteName;

        // Refresh tree
        if (UIHelper.DisplayArchivedIcon(siteName) || UIHelper.DisplayPublishedIcon(siteName) || UIHelper.DisplayNotPublishedIcon(siteName))
        {
            ScriptHelper.RegisterStartupScript(this, typeof(string), "refreshTree", ScriptHelper.GetScript("RefreshTree(" + Node.NodeParentID + ", " + Node.NodeID + ");"));
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Performs necessary checks and archives document.
    /// </summary>
    /// <returns>TRUE if operation fails and whole process should be canceled.</returns>
    private bool PerformArchive(WorkflowManager wm, TreeProvider tree, TreeNode node, string aliasPath)
    {
        if (node != null)
        {
            if (!UndoPossibleCheckOut(tree, node))
            {
                return(true);
            }
            try
            {
                if (currentUser.UserHasAllowedCultures && !currentUser.IsCultureAllowed(node.DocumentCulture, node.NodeSiteName))
                {
                    AddLog(string.Format(GetString("content.notallowedtomodifycultureversion"), node.DocumentCulture, node.NodeAliasPath));
                }
                else
                {
                    // Add log record
                    AddLog(HTMLHelper.HTMLEncode(node.NodeAliasPath + " (" + node.DocumentCulture + ")"));

                    // Archive document
                    wm.ArchiveDocument(node, string.Empty);
                }
            }
            catch
            {
                AddLog(string.Format(ResHelper.GetString("content.archivenowf"), HTMLHelper.HTMLEncode(node.NodeAliasPath + " (" + node.DocumentCulture + ")")));
            }
            return(false);
        }
        else
        {
            AddLog(string.Format(ResHelper.GetString("ContentRequest.DocumentNoLongerExists", currentCulture), HTMLHelper.HTMLEncode(aliasPath)));
            return(false);
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Moves the document to the Archived step in the workflow process. Called when the "Archive document" button is pressed.
    /// Expects the "CreateExampleObjects" method to be run first.
    /// </summary>
    private bool ArchiveDocument()
    {
        TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);

        // Prepare parameters
        string siteName  = CMSContext.CurrentSiteName;
        string aliasPath = "/API-Example";
        string culture   = "en-us";
        bool   combineWithDefaultCulture = false;
        string classNames = TreeProvider.ALL_CLASSNAMES;

        string where = null;
        string orderBy             = null;
        int    maxRelativeLevel    = -1;
        bool   selectOnlyPublished = false;
        string columns             = null;

        // Get the document
        TreeNode node = DocumentHelper.GetDocument(siteName, aliasPath, culture, combineWithDefaultCulture, classNames, where, orderBy, maxRelativeLevel, selectOnlyPublished, columns, tree);

        if (node != null)
        {
            WorkflowManager workflowManager = WorkflowManager.GetInstance(tree);

            WorkflowInfo workflow = workflowManager.GetNodeWorkflow(node);

            // Check if the document uses workflow
            if (workflow != null)
            {
                // Archive the document
                workflowManager.ArchiveDocument(node, null);

                return(true);
            }
            else
            {
                apiArchiveDocument.ErrorMessage = "The document doesn't use workflow.";
            }
        }

        return(false);
    }
Ejemplo n.º 4
0
        //Delete the document if that is not published
        public static void DeleteDocument(TreeProvider tree, TreeNode node)
        {
            WorkflowManager workflowManager     = WorkflowManager.GetInstance(tree);
            WorkflowInfo    workflow            = workflowManager.GetNodeWorkflow(node);
            var             isPublishedDocument = node.PublishedVersionExists;

            // Check if the document uses workflow
            if (workflow != null)
            {
                if (isPublishedDocument)
                {
                    // Archive the document
                    workflowManager.ArchiveDocument(node, null);
                }
                else
                {
                    //if document is not published then permanetly delete it
                    node.Destroy();
                }
            }
        }
Ejemplo n.º 5
0
        //move that document to previous version workflow state
        //it will move to the state or previous version that we edited
        protected static bool MoveToWorkflowStep(int VersionWorkFlowStepID, TreeProvider tree, TreeNode node)
        {
            bool versionChangedStatus = false;

            WorkflowManager workflowManager = WorkflowManager.GetInstance(tree);
            WorkflowInfo    workflow        = workflowManager.GetNodeWorkflow(node);

            // Check if the document uses workflow
            if (workflow != null)
            {
                // Check if the workflow doesn't use automatic publishing, otherwise, documents can't change workflow steps.
                if (!workflow.WorkflowAutoPublishChanges)
                {
                    // Check if the current user can move the document to the next step
                    if (workflowManager.CheckStepPermissions(node, WorkflowActionEnum.Reject))
                    {
                        // Get workflowStepInfo object based on workflow step ID
                        WorkflowStepInfo workflowStep = WorkflowStepInfoProvider.GetWorkflowStepInfo(VersionWorkFlowStepID);
                        if (workflowStep.StepDisplayName.ToLower() == SMEConstant.WORKFLOW_PUBLISHED.ToLower())
                        {
                            // Move the document to the specified step
                            workflowManager.MoveToSpecificStep(node, workflowStep);
                            versionChangedStatus = true;
                        }
                        else if (workflowStep.StepDisplayName.ToLower() == SMEConstant.WORKFLOW_ARCHIVED.ToLower())
                        {
                            // Archive the document
                            workflowManager.ArchiveDocument(node, null);
                            // Move the document to the specified step
                            //workflowManager.MoveToSpecificStep(node, workflowStep);
                            versionChangedStatus = true;
                        }
                    }
                }
            }
            return(versionChangedStatus);
        }
    /// <summary>
    /// Performs necessary checks and archives document.
    /// </summary>
    /// <returns>TRUE if operation fails and whole process should be canceled.</returns>
    private bool PerformArchive(WorkflowManager wm, TreeProvider tree, TreeNode node, string aliasPath)
    {
        if (node != null)
        {
            if (!UndoPossibleCheckOut(tree, node))
            {
                return true;
            }
            try
            {
                if (currentUser.UserHasAllowedCultures && !currentUser.IsCultureAllowed(node.DocumentCulture, node.NodeSiteName))
                {
                    AddLog(string.Format(GetString("content.notallowedtomodifycultureversion"), node.DocumentCulture, node.NodeAliasPath));
                }
                else
                {
                    // Add log record
                    AddLog(HTMLHelper.HTMLEncode(node.NodeAliasPath + " (" + node.DocumentCulture + ")"));

                    // Archive document
                    wm.ArchiveDocument(node, string.Empty);
                }
            }
            catch (ThreadAbortException te)
            {
                AddLog(te.Message);
            }
            catch
            {
                AddLog(string.Format(ResHelper.GetString("content.archivenowf"), HTMLHelper.HTMLEncode(node.NodeAliasPath + " (" + node.DocumentCulture + ")")));
            }
            return false;
        }
        else
        {
            AddLog(string.Format(ResHelper.GetString("ContentRequest.DocumentNoLongerExists", currentCulture), HTMLHelper.HTMLEncode(aliasPath)));
            return false;
        }
    }
    /// <summary>
    /// Archives sub documents of given node.
    /// </summary>
    /// <param name="parentNode">Parent node</param>
    /// <param name="tree">Tree provider</param>
    /// <param name="wm">Workflow manager</param>
    /// <param name="cultureCode">Culture code</param>
    /// <param name="siteName">Site name</param>
    private void ArchiveSubDocuments(TreeNode parentNode, TreeProvider tree, WorkflowManager wm, string cultureCode, string siteName)
    {
        string columns = SqlHelperClass.MergeColumns(TreeProvider.SELECTNODES_REQUIRED_COLUMNS, "NodeAliasPath, ClassName, DocumentCulture");

        // Get subdocuments
        DataSet subDocuments = tree.SelectNodes(siteName, parentNode.NodeAliasPath + "/%", cultureCode, false, null, null, null, TreeProvider.ALL_LEVELS, false, 0, columns);
        if (!DataHelper.DataSourceIsEmpty(subDocuments))
        {
            foreach (DataRow nodeRow in subDocuments.Tables[0].Rows)
            {
                // Get the current document
                string className = ValidationHelper.GetString(nodeRow["ClassName"], string.Empty);
                string aliasPath = ValidationHelper.GetString(nodeRow["NodeAliasPath"], string.Empty);
                string docCulture = ValidationHelper.GetString(nodeRow["DocumentCulture"], string.Empty);
                TreeNode node = DocumentHelper.GetDocument(siteName, aliasPath, docCulture, false, className, null, null, TreeProvider.ALL_LEVELS, false, null, tree);

                if (node == null)
                {
                    AddLog(string.Format(ResHelper.GetString("ContentRequest.DocumentNoLongerExists", currentCulture), HTMLHelper.HTMLEncode(aliasPath)));
                    continue;
                }

                if (!UndoPossibleCheckOut(tree, node))
                {
                    return;
                }

                try
                {
                    // Try to get workflow scope
                    wm.GetStepInfo(node);

                    // Add log record
                    AddLog(HTMLHelper.HTMLEncode(node.NodeAliasPath + " (" + node.GetValue("DocumentCulture") + ")"));

                    // Archive document
                    wm.ArchiveDocument(node, string.Empty);
                }
                catch
                {
                    AddLog(string.Format(ResHelper.GetString("content.archivenowf"), HTMLHelper.HTMLEncode(node.NodeAliasPath + " (" + node.GetValue("DocumentCulture") + ")")));
                    continue;
                }
            }
        }
    }
    /// <summary>
    /// Archives document(s).
    /// </summary>
    private void ArchiveAll(object parameter)
    {
        if (parameter == null)
        {
            return;
        }

        TreeProvider tree = new TreeProvider(currentUser);
        tree.AllowAsyncActions = false;

        try
        {
            // Begin log
            AddLog(ResHelper.GetString("content.archivingdocuments", currentCulture));

            string[] parameters = ((string)parameter).Split(';');

            string siteName = parameters[1];

            // Get identifiers
            int[] workNodes = nodeIds.ToArray();

            // Prepare the where condition
            string where = SqlHelperClass.GetWhereCondition("NodeID", workNodes);
            string columns = SqlHelperClass.MergeColumns(TreeProvider.SELECTNODES_REQUIRED_COLUMNS, "NodeAliasPath, ClassName, DocumentCulture");

            // Get cultures
            string cultureCode = chkAllCultures.Checked ? TreeProvider.ALL_CULTURES : parameters[0];

            // Get the documents
            DataSet documents = tree.SelectNodes(siteName, "/%", cultureCode, false, null, where, "NodeAliasPath DESC", TreeProvider.ALL_LEVELS, false, 0, columns);

            // Create instance of workflow manager class
            WorkflowManager wm = new WorkflowManager(tree);

            if (!DataHelper.DataSourceIsEmpty(documents))
            {
                foreach (DataRow nodeRow in documents.Tables[0].Rows)
                {
                    // Get the current document
                    string className = ValidationHelper.GetString(nodeRow["ClassName"], string.Empty);
                    string aliasPath = ValidationHelper.GetString(nodeRow["NodeAliasPath"], string.Empty);
                    string docCulture = ValidationHelper.GetString(nodeRow["DocumentCulture"], string.Empty);
                    TreeNode node = DocumentHelper.GetDocument(siteName, aliasPath, docCulture, false, className, null, null, -1, false, null, tree);

                    if (node == null)
                    {
                        AddLog(string.Format(ResHelper.GetString("ContentRequest.DocumentNoLongerExists", currentCulture), HTMLHelper.HTMLEncode(aliasPath)));
                        continue;
                    }

                    if (!UndoPossibleCheckOut(tree, node))
                    {
                        return;
                    }

                    try
                    {
                        // Try to get workflow scope
                        wm.GetStepInfo(node);

                        // Add log record
                        AddLog(HTMLHelper.HTMLEncode(node.NodeAliasPath + " (" + node.GetValue("DocumentCulture") + ")"));

                        // Archive document
                        wm.ArchiveDocument(node, string.Empty);
                    }
                    catch
                    {
                        AddLog(string.Format(ResHelper.GetString("content.archivenowf"), HTMLHelper.HTMLEncode(node.NodeAliasPath + " (" + node.GetValue("DocumentCulture") + ")")));
                    }

                    // Process underlying documents
                    if (chkUnderlying.Checked && (node.NodeChildNodesCount > 0))
                    {
                        ArchiveSubDocuments(node, tree, wm, cultureCode, siteName);
                    }
                }
            }
            else
            {
                AddError(ResHelper.GetString("content.nothingtoarchive", currentCulture));
            }
        }
        catch (ThreadAbortException ex)
        {
            string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty);
            if (state != CMSThread.ABORT_REASON_STOP)
            {
                // Log error
                LogExceptionToEventLog(ResHelper.GetString("content.archivefailed", currentCulture), ex);
            }
        }
        catch (Exception ex)
        {
            // Log error
            LogExceptionToEventLog(ResHelper.GetString("content.archivefailed", currentCulture), ex);
        }
    }
Ejemplo n.º 9
0
    /// <summary>
    /// Moves the document to the Archived step in the workflow process. Called when the "Archive document" button is pressed.
    /// Expects the "CreateExampleObjects" method to be run first.
    /// </summary>
    private bool ArchiveDocument()
    {
        TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);

        // Prepare parameters
        string siteName = CMSContext.CurrentSiteName;
        string aliasPath = "/API-Example";
        string culture = "en-us";
        bool combineWithDefaultCulture = false;
        string classNames = TreeProvider.ALL_CLASSNAMES;
        string where = null;
        string orderBy = null;
        int maxRelativeLevel = -1;
        bool selectOnlyPublished = false;
        string columns = null;

        // Get the document
        TreeNode node = DocumentHelper.GetDocument(siteName, aliasPath, culture, combineWithDefaultCulture, classNames, where, orderBy, maxRelativeLevel, selectOnlyPublished, columns, tree);

        if (node != null)
        {
            WorkflowManager workflowManager = new WorkflowManager(tree);

            WorkflowInfo workflow = workflowManager.GetNodeWorkflow(node);

            // Check if the document uses workflow
            if (workflow != null)
            {
                // Archive the document
                workflowManager.ArchiveDocument(node, null);

                return true;
            }
            else
            {
                apiArchiveDocument.ErrorMessage = "The document doesn't use workflow.";
            }
        }

        return false;
    }