More in this section

Forums / Developing with Sitefinity / Page Rollback: From Draft to Previous Version

Page Rollback: From Draft to Previous Version

9 posts, 0 answered
  1. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    02 Mar 2010
    Link to this post
    Continuing on the progress we made in the previous post, the next step is reverting a page in a checked in, Draft state back to its previous version before changes were made

    I've spent several hours experimenting with no luck. The documentation offers no guidance. I'm wondering how you would approach it.

    We know that the VersionManager doesn't work on page items, however, Rodoslav mentioned a page "copy" method for 3.7 SP2. I'm running that version, if that method is useful.

    Thanks,
    Jeff
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    02 Mar 2010
    Link to this post
    Hi Jeff,

    1. The forum post shows how to use VesionManager and working with object's versions.

    2. You can use the UI to perform Restore. Note that the highlighted button should be visible and not commented.

    <asp:GridView ID="GridView1" AllowPaging="true" PageSize="20" AutoGenerateColumns="false" GridLines="none" CssClass="listItems history" runat="server">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:HyperLink ID="PreviewLink" runat="server"><asp:Literal runat="server" Text="<%$Resources:View %>"></asp:Literal></asp:HyperLink
                        <asp:LinkButton ID="RollbackButton" runat="server"><asp:Literal runat="server" Text="<%$Resources:RollBack %>"></asp:Literal></asp:LinkButton>
                        <asp:LinkButton ID="RestoreButton" runat="server"><asp:Literal ID="Literal1" runat="server" Text="Restore"></asp:Literal></asp:LinkButton>
                    </ItemTemplate>
                    <ItemStyle CssClass="gridActions" />
                </asp:TemplateField>
                <asp:BoundField DataField="Version" HeaderText="<%$Resources:Version %>"><ItemStyle CssClass="gridContentTitle" /></asp:BoundField>
                <asp:BoundField DataField="Stamp" HeaderText="<%$Resources:Date %>" HeaderStyle-CssClass="GridHeader_SiteFinity" DataFormatString="<%$Resources:VersionDateFormat %>" HtmlEncode="false" />
                <asp:BoundField DataField="Modifier" HeaderText="<%$Resources:Author %>" HeaderStyle-CssClass="GridHeader_SiteFinity" />
                <asp:BoundField DataField="Theme" HeaderText="<%$Resources:Theme %>"><ItemStyle /></asp:BoundField>
            </Columns>
        </asp:GridView>

    programmatically restoring a page

    IStagedPage staged = this.iPage.GetVersion(version);
    staged = staged.CheckOut();
    staged.CheckIn();


    Greetings,
    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
    03 Mar 2010
    Link to this post
    Thanks for the quick response.

    Can I get a complete code sample? I'm not sure how to apply it since ICmsPage.Staged is a read-only property.

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    03 Mar 2010
    Link to this post
    Hi Jeff,

    Below is a sample code that will do restore - a new version will be created( copy )

    // pass the page and its version to a private method
     
    private void Restore(int version, ICmsPage p)
    {
     
        IStagedPage staged = p.gGetVersion(version);
        staged = staged.CheckOut();
        staged.CheckIn();
        OnRestore(EventArgs.Empty);
    }


    Best wishes,
    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
    11 Mar 2010
    Link to this post
    Hi Ivan,

    I'm back.

    The latest sample isn't working. No new version of the page is created and the current version is unchanged.

    Is there something in the "OnRestore" event that finishes the job? I'm not privy to what's in that event or how to call it.

    Thanks,
    Jeff
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    12 Mar 2010
    Link to this post
    Hi Jeff,

    OnResote is used when the Grid is rebind. I slightly modified the code at my end and it is working correctly. It performs restore of version 3 for the specified page.

    var manager = new CmsManager();
    ICmsPage p = (ICmsPage)manager.GetPage(new Guid("797aa331-7edf-4dc1-9c92-80e8ccf12bcd"), true);
    IStagedPage s = p.GetVersion(3);
    IStagedPage st = s.CheckOut();
    st.CheckIn();


    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.
  7. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    12 Mar 2010
    Link to this post
    Ivan,

    You have given me the same code sample (from a functional standpoint) three times in a row. It doesn't work.

    Can you please test this out yourself so we don't keep going around in circles?

    Thanks,
    Jeff
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    14 Mar 2010
    Link to this post
    Hello Jeff,

    I have tested the code several times. Take a look at the attached video prepared for your convenience. I am not sure why the code does not work for you. Note that this code restore - copy a page version by creating a new one.

    Sincerely yours,
    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.
  9. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    15 Mar 2010
    Link to this post
    I see that it is working for you and I appreciate that you even went through the trouble to produce a video. At this point, I guess we just need to figure out why I don't get the same results.

    I couldn't tell from the video if you have workflow enabled. If it is, I could not see the page status. In my case, I am trying to go from a "Draft" status to a previous version.

    Can you confirm that this code sample works under the same conditions for you?

    Also, I see you page "Rollback" and "Restore" links next to every version on the History page. I only have Roll back. Could this be factor? Does my lack of a Restore link mean there's a feature that I haven't enabled that could be preventing the code from working?

    Thanks for your continued efforts on this issue.

    Jeff
Register for webinar
9 posts, 0 answered