Esempio n. 1
0
    /// <summary>
    /// Deletes a specified document version. Called when the "Delete version" button is pressed.
    /// Expects the "CreateExampleObjects" and at least the "EditDocument" method to be run first.
    /// </summary>
    private bool DeleteVersion()
    {
        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)
        {
            // Prepare the WHERE condition for the latest document version
            where   = "DocumentID = " + node.DocumentID;
            orderBy = "ModifiedWhen DESC";
            int topN = 1;

            // Get the version ID
            DataSet versionHistory = VersionHistoryInfoProvider.GetVersionHistories(where, orderBy, topN, columns);

            if (!DataHelper.DataSourceIsEmpty(versionHistory))
            {
                // Create the Version history info object
                VersionHistoryInfo version = new VersionHistoryInfo(versionHistory.Tables[0].Rows[0]);

                VersionManager versionManager = VersionManager.GetInstance(tree);

                // Delete the version
                versionManager.DestroyDocumentVersion(version.VersionHistoryID);

                return(true);
            }
            else
            {
                apiDeleteVersion.ErrorMessage = "The document's version history is empty.";
            }
        }

        return(false);
    }
Esempio n. 2
0
    protected void gridHistory_OnAction(string actionName, object actionArgument)
    {
        int versionHistoryId = ValidationHelper.GetInteger(actionArgument, 0);

        switch (actionName.ToLowerInvariant())
        {
        case "rollback":
            if (versionHistoryId > 0)
            {
                if (CheckedOutByUserID > 0)
                {
                    // Document is checked out
                    ShowError(GetString("VersionProperties.CannotRollbackCheckedOut"));
                }
                else
                {
                    // Check permissions
                    if (!WorkflowManager.CheckStepPermissions(Node, WorkflowActionEnum.Approve) || !CanModify || (CheckedOutByAnotherUser && !CanCheckIn) || (versionHistoryId == Node.DocumentCheckedOutVersionHistoryID))
                    {
                        ShowError(String.Format(GetString("cmsdesk.notauthorizedtoeditdocument"), HTMLHelper.HTMLEncode(Node.GetDocumentName())));
                    }
                    else
                    {
                        try
                        {
                            VersionManager.RollbackVersion(versionHistoryId);

                            if (!IsLiveSite)
                            {
                                // Refresh content tree (for the case that document name has been changed)
                                ScriptHelper.RefreshTree(Page, NodeID, Node.NodeParentID);
                            }

                            // Refresh node instance
                            InvalidateNode();
                            ShowConfirmation(GetString("VersionProperties.RollbackOK"));
                        }
                        catch (Exception ex)
                        {
                            ShowError(ex.Message);
                        }
                    }
                }
            }
            break;

        case "destroy":
            if (versionHistoryId > 0)
            {
                if (Node != null)
                {
                    // Check permissions
                    if (!CanDestroy || (CheckedOutByAnotherUser && !CanCheckIn) || (versionHistoryId == Node.DocumentCheckedOutVersionHistoryID))
                    {
                        ShowError(GetString("History.ErrorNotAllowedToDestroy"));
                    }
                    else
                    {
                        // Refresh node instance
                        InvalidateNode();
                        VersionManager.DestroyDocumentVersion(versionHistoryId);
                        ShowConfirmation(GetString("VersionProperties.DestroyOK"));
                    }
                }
            }
            break;
        }
    }
Esempio n. 3
0
    protected void gridHistory_OnAction(string actionName, object actionArgument)
    {
        int versionHistoryId = ValidationHelper.GetInteger(actionArgument, 0);

        switch (actionName.ToLower())
        {
        case "rollback":
            if (versionHistoryId > 0)
            {
                if (CheckedOutByUserID > 0)
                {
                    // Document is checked out
                    ErrorLabel.Text += GetString("VersionProperties.CannotRollbackCheckedOut");
                }
                else
                {
                    // Check permissions
                    if (!CanApprove || !CanModify)
                    {
                        ErrorLabel.Text = String.Format(GetString("cmsdesk.notauthorizedtoeditdocument"), Node.NodeAliasPath);
                    }
                    else
                    {
                        try
                        {
                            VersionManager.RollbackVersion(versionHistoryId);

                            if (!IsLiveSite)
                            {
                                // Refresh content tree (for the case that document name has been changed)
                                string refreshTreeScript = ScriptHelper.GetScript("if(window.RefreshTree!=null)RefreshTree(" + Node.NodeParentID + ", " + Node.NodeID + ");");
                                ScriptHelper.RegisterStartupScript(this, typeof(string), "refreshTree" + ClientID, refreshTreeScript);
                            }

                            InfoLabel.Text = GetString("VersionProperties.RollbackOK");
                        }
                        catch (Exception ex)
                        {
                            ErrorLabel.Text += ex.Message;
                        }
                    }
                }
            }
            break;

        case "destroy":
            if (versionHistoryId > 0)
            {
                if (Node != null)
                {
                    // Check permissions
                    if (!CanDestroy || (CheckedOutByAnotherUser && !CanCheckIn))
                    {
                        ErrorLabel.Text = GetString("History.ErrorNotAllowedToDestroy");
                    }
                    else
                    {
                        VersionManager.DestroyDocumentVersion(versionHistoryId);
                        InfoLabel.Text = GetString("VersionProperties.DestroyOK");
                    }
                }
            }
            break;
        }
    }
Esempio n. 4
0
    /// <summary>
    /// Deletes a specified document version. Called when the "Delete version" button is pressed.
    /// Expects the "CreateExampleObjects" and at least the "EditDocument" method to be run first.
    /// </summary>
    private bool DeleteVersion()
    {
        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)
        {
            // Prepare the WHERE condition for the latest document version
            where = "DocumentID = " + node.DocumentID;
            orderBy = "ModifiedWhen DESC";
            int topN = 1;

            // Get the version ID
            DataSet versionHistory = VersionHistoryInfoProvider.GetVersionHistories(where, orderBy, topN, columns);

            if (!DataHelper.DataSourceIsEmpty(versionHistory))
            {
                // Create the Version history info object
                VersionHistoryInfo version = new VersionHistoryInfo(versionHistory.Tables[0].Rows[0]);

                VersionManager versionManager = new VersionManager(tree);

                // Delete the version
                versionManager.DestroyDocumentVersion(version.VersionHistoryID);

                return true;
            }
            else
            {
                apiDeleteVersion.ErrorMessage = "The document's version history is empty.";
            }
        }

        return false;
    }