More in this section

Forums / Developing with Sitefinity / Bug Report: Staged.IsCheckedOut Inconsistency

Bug Report: Staged.IsCheckedOut Inconsistency

5 posts, 0 answered
  1. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    16 Mar 2010
    Link to this post
    Hello,

    I came across an inconsistency with the IStagedPage.IsCheckedOut flag that I had to work around in my code.

    After checking out a page, IsCheckedOut is still false. However, any other action related to Check In/Out is immediately reflected by this flag.

    For example, when you call CheckIn, IsCheckedOut is set to false immediately after the call. Same is true for UndoCheckOut.

    CheckOut has no effect on the IsCheckedOut flag until after the Nolics transaction is committed.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 Mar 2010
    Link to this post
    Hi Jeff,

    Could you send the code you use or a sample code that illustrates this issue, so we could add it to the bug report and fix the problem for the next SP.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    31 Mar 2010
    Link to this post
    I'm happy to provide sample code. I have a test harness I use for testing CMS-related issues outside of my development code.

    Just create a new aspx/aspx.cs page and paste the following code into it. The code also shows the rollback issue that I still need assistance on.

    To demonstrate the problem, click the "Create Page" button, then click the "Check Out" button.

    If you watch in the debugger, after Staged.CheckOut() is called, IsCheckedOut is still false. After the Nolics transaction is committed, IsCheckedOut is true.

    CMSTest.aspx.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Cms;
    using Telerik.Cms.Web;
    using Telerik.Workflow;
    using Telerik.Cms.Engine;
    using Telerik.Versioning;
    using System.Globalization;
    using Telerik.Cms.Data;
     
    public partial class CMSTest : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Form.Controls.Add(new LiteralControl(string.Format("<p>{0}</p>",
                    Request.RawUrl)));
        }
        protected void btnCreate_Click(object sender, EventArgs e)
        {
            CmsManager Manager = new CmsManager();
     
            // create a new instance of CmsManager with default provider
            IPage NewPage = Manager.CreatePage(CurrentDateAndTime, Guid.Empty);
     
            if (NewPage.ID == Guid.Empty)
                return;
     
            TextBox2.Text = NewPage.ID.ToString();
     
            Manager.SavePage(NewPage);
     
            ICmsPage CmsPage = (ICmsPage)Manager.GetPage(NewPage.ID, true);
     
            if (CmsPage == null)
                return;
     
            CmsPage.MasterPage = "Default.master";
     
            CmsPage.Title = CurrentDateAndTime;
     
            IStagedPage staged = CmsPage.Staged.CheckOut();
            Guid templateId = ((IPageTemplate)Manager.GetTemplates()[0]).ID;
            staged.SetTemplate(templateId, "Dummy");
     
            staged.MasterPage = CmsPage.MasterPage;
     
            staged.AddControl("Content",
                    new LiteralControl("<p id=\"pComingSoon\">This page is coming soon. Stay tuned!</p>"));
     
            Manager.SavePage((IPage)CmsPage);
     
            CmsPage = (ICmsPage)Manager.GetPage(NewPage.ID, true);
            staged.CheckIn();
     
            CmsPage.Publish();
        }
     
        protected void btnCheckOut_Click(object sender, EventArgs e)
        {
            CmsManager Manager = new CmsManager();
     
            ICmsPage ThePage = (ICmsPage)Manager.GetPage(new Guid(TextBox2.Text), true);
     
            if (!ThePage.Staged.IsCheckedOut)
                ThePage.Staged.CheckOut();
        }
     
        private string CurrentDateAndTime
        {
            get
            {
                return string.Format("ItsTime-{0}-{1:00}{2:00}-{3:00}-{4:00}-{5:00}",
                    DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour,
                    DateTime.Now.Minute, DateTime.Now.Second);
            }
        }
        protected void btnAddContent_Click(object sender, EventArgs e)
        {
            CmsManager Manager = new CmsManager();
            ICmsPage ThePage = (ICmsPage)Manager.GetPage(new Guid(TextBox2.Text), true);
     
            if (ThePage.Staged.IsCheckedOut)
            {
                IStagedPage staged = ThePage.Staged;
                staged.AddControl("Content",
                    new LiteralControl("<p>This page was updated on " + CurrentDateAndTime + "</p>"));
     
                Manager.SavePage(ThePage);
            }
        }
        protected void btnRollback_Click(object sender, EventArgs e)
        {
            CmsManager Manager = new CmsManager();
            ICmsPage ThePage = (ICmsPage)Manager.GetPage(new Guid(TextBox2.Text), true);
     
            ThePage.Staged.Rollback();
     
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            CmsManager Manager = new CmsManager();
            ICmsPage ThePage = (ICmsPage)Manager.GetPage(new Guid(TextBox2.Text), true);
            Manager.SavePage(ThePage);
        }
     
        protected void btnCheckIn_Click(object sender, EventArgs e)
        {
            CmsManager Manager = new CmsManager();
            ICmsPage ThePage = (ICmsPage)Manager.GetPage(new Guid(TextBox2.Text), true);
     
            if (ThePage.Staged.IsCheckedOut)
                ThePage.Staged.CheckIn();
     
        }
        protected void btnPublsh_Click(object sender, EventArgs e)
        {
            CmsManager Manager = new CmsManager();
            ICmsPage ThePage = (ICmsPage)Manager.GetPage(new Guid(TextBox2.Text), true);
     
            WorkflowInstance workflow = ThePage.GetWorkflow();
            if (workflow != null)
            {
                PageWorkflow activity = (PageWorkflow)workflow.Activity;
                if (activity.ApprovalStatus != ApprovalStatus.Published)
                {
                    ExecuteActivity(ThePage.WorkflowID, "SendForApproval");
                    Nolics.ORMapper.Base.DataConnection.InitWebRequest();
                    ExecuteActivity(ThePage.WorkflowID, "Approve");
                    Nolics.ORMapper.Base.DataConnection.InitWebRequest();
                }
            }
            Manager.SavePage(ThePage);
     
            ThePage = (ICmsPage)Manager.GetPage(new Guid(TextBox2.Text), true);
            ThePage.Publish();
     
        }
     
        private void ExecuteActivity(Guid id, string activityName)
        {
            WorkflowInstance instance = WorkflowRuntime.Instance.GetWorkflow(id);
     
            if (instance != null)
            {
                PageWorkflow workflow = (PageWorkflow)instance.Activity;
     
     
     
                EventActivity activity = FindActivity(activityName, workflow.Activities);
     
                if (activity != null)
                {
                    activity.Execute(WorkflowRuntime.Instance);
                }
            }
        }
     
        private EventActivity FindActivity(string name, IList<Activity> activities)
        {
            foreach (Activity act in activities)
            {
                if ((act is EventActivity) && (((EventActivity)act).CommandName == name))
                    return (EventActivity)act;
     
                EventActivity ea = FindActivity(name, act.Activities);
     
                if (ea != null)
                    return ea;
            }
     
            return null;
        }
        protected void btnCancelChanges_Click(object sender, EventArgs e)
        {
     
            var manager = new CmsManager();
            ICmsPage p = (ICmsPage)manager.GetPage(new Guid(TextBox2.Text), true);
            IStagedPage s = p.GetVersion(3);
            IStagedPage st = s.CheckOut();
            st.CheckIn();
     
            return;
            CmsManager Manager = new CmsManager();
            ICmsPage ThePage = (ICmsPage)Manager.GetPage(new Guid(TextBox2.Text), true);
     
            IStagedPage staged = ThePage.GetVersion(1);
     
     
            staged = staged.CheckOut();
     
            return;
     
            // Alternative to rollback. Works but it should be easier/more efficient
            foreach (CmsWebControl wc in ThePage.Staged.Controls)
            {
                ThePage = (ICmsPage)Manager.GetPage(ThePage.ID, true);
                ThePage.Staged.RemoveControl(wc);
            }
     
            foreach (CmsWebControl c in staged.Controls)
            {
                Control ccopy = c.LoadControl();
                ThePage = (ICmsPage)Manager.GetPage(ThePage.ID, true);
                ThePage.Staged.AddControl(c.ContainerID, ccopy);
                ThePage = (ICmsPage)Manager.GetPage(ThePage.ID, true);
                ThePage.Staged.AddControl(c.ContainerID, new LiteralControl("<p>Reverted</p>"));
            }
     
            Manager.SavePage(ThePage);
     
            //ThePage = (ICmsPage)Manager.GetPage(new Guid(TextBox2.Text), true);
            //ThePage.Staged.CheckIn();
        }
        protected void btnClearContainer_Click(object sender, EventArgs e)
        {
            TextBox2.Text = "93793f3f-5c7d-4434-9958-9487b628aed3";
            CmsManager Manager = new CmsManager();
            ICmsPage ThePage = (ICmsPage)Manager.GetPage(new Guid(TextBox2.Text), true);
     
            IStagedPage staged = ThePage.Staged;
     
            // Remove old page content
            foreach (CmsWebControl wc in staged.Controls)
            {
                if (wc.ContainerID == "cphFileHighlights")
                {
                    ThePage = (ICmsPage)Manager.GetPage(new Guid(TextBox2.Text), true);
                    staged.RemoveControl(wc);
                }
            }
     
            ThePage = (ICmsPage)Manager.GetPage(new Guid(TextBox2.Text), true);
            Manager.SavePage(ThePage);
            //staged.CheckIn();
     
            WorkflowInstance workflow = ThePage.GetWorkflow();
            if (workflow != null)
            {
                PageWorkflow activity = (PageWorkflow)workflow.Activity;
                if (activity.ApprovalStatus != ApprovalStatus.Published)
                {
                    ExecuteActivity(ThePage.WorkflowID, "SendForApproval");
                    Nolics.ORMapper.Base.DataConnection.InitWebRequest();
                    ExecuteActivity(ThePage.WorkflowID, "Approve");
                    Nolics.ORMapper.Base.DataConnection.InitWebRequest();
                }
            }
            Manager.SavePage(ThePage);
     
            ThePage = (ICmsPage)Manager.GetPage(new Guid(TextBox2.Text), true);
            ThePage.Publish();
        }
    }


    CMSText.aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="CMSTest.aspx.cs" Inherits="CMSTest" %>
     
    <%@ Register assembly="Telerik.OpenAccess, Version=2009.3.1119.2, Culture=neutral, PublicKeyToken=7ce17eeaf1d59342" namespace="Telerik.OpenAccess" tagprefix="telerik" %>
    <%@ Register assembly="System.Web.DynamicData, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.DynamicData" tagprefix="cc1" %>
    <%@ Register assembly="System.Web.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" namespace="System.Web.UI.WebControls" tagprefix="asp" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Button ID="btnCreate" runat="server" Text="CreatePage"
                onclick="btnCreate_Click" />
            <asp:Button ID="btnCheckOut"
                runat="server" Text="Check Out" onclick="btnCheckOut_Click" />
            <asp:Button ID="btnAddContent" runat="server" Text="Add Content"
                onclick="btnAddContent_Click" />
            <asp:Button ID="btnRollback" runat="server" Text="Rollback"
                onclick="btnRollback_Click" style="height: 26px" />
            <asp:Button ID="btnSave"
                runat="server" Text="Save" onclick="btnSave_Click" />
            <asp:Button ID="btnCheckIn" runat="server" Text="Check In"
                onclick="btnCheckIn_Click" />
            <asp:Button ID="btnCancelChanges" runat="server"
                onclick="btnCancelChanges_Click" Text="Cancel Changes" />
    <asp:Button ID="btnPublsh" runat="server" Text="btnPublish" onclick="btnPublsh_Click" />
    <p> </p>
            <asp:TextBox ID="TextBox1" runat="server" Rows="5" TextMode="MultiLine"
                Width="450px"></asp:TextBox>
        </div>
         
        <hr style="border: none" />
         
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
         
        <br />
        <br />
        <asp:Button ID="btnClearContainer" runat="server"
            onclick="btnClearContainer_Click" Text="Clear Container" />
         
        </form>
    </body>
    </html>
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    13 Apr 2010
    Link to this post
    Hello Jeff,

    We made a simple test

    ICmsPage page1 = (ICmsPage)manager.GetPage(new Guid(node.Key), true);
    // returns staged version. The new staged version is different.
    IStagedPage staged = page1.Staged.CheckOut();
    // true
    bool ch = staged.IsCheckedOut;

    and the code returns true (staged.IsCheckedOut)

    Regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    13 Apr 2010
    Link to this post
    It's working when I use your code. Mine is slightly different in that I don't create a separate variable for the staged page. I'm looking directly at page1.Staged.IsCheckedOut.

    Here's a test that should reproduce the problem for you:
    CmsManager Manager = new CmsManager();
     
    ICmsPage ThePage = (ICmsPage)Manager.GetPage(new Guid(TextBox2.Text), true);
     
    ThePage.Staged.CheckOut();
     
    bool bCheckedout = ThePage.Staged.IsCheckedOut;

    This is how I typically access the staged page. I tend not to create a separate variable when I can access it directly through another.
Register for webinar
5 posts, 0 answered