1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / how to publish a PageDraft and have it appear in revision history

how to publish a PageDraft and have it appear in revision history

6 posts, 0 answered
  1. Justin
    Justin avatar
    4 posts
    Registered:
    26 May 2011
    28 Jun 2011
    Link to this post
    I'm trying to work out how to properly republish a page.
    We need to do this accross all pages on the site (corporate Intranet - approx 1900 migrated pages from 3.7 --> 4.1)

    an issue we discovered is that the migrated pages show NOTHING in revision history until they are edited and published again (i raised this as an issue into PITS previously).  we believe this is behind a few different issues we are trying to work through, for example they can't be unpublished in this state.

    I have created new clean 4.1 site with 6 pages, in an effort to work out how to do this correcly.
    I am trying as follows:
     
    public static string RepublishAllPages()
    {
        string result = "";
     
        var pageNodes = App.WorkWith()
                                        .Pages()
                                        .LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
                                        .Get()
                                        .Where(pN => pN.Page.Status == ContentLifecycleStatus.Live)
                                        .ToList();
     
        foreach (PageNode p in pageNodes)
        {
            var myId = p.Page.Id;     
            var myDraft = m_PageManager.EditPage(myId, true);
            m_PageManager.PublishPageDraft(myDraft, true);
            result += p.Page.Title + " published";
            m_PageManager.SaveChanges();
             
        }
     
     
        return result;
    }

    It appears to work but nothing appears in the revision history.

    What am i missing?

    Additionally, we need to programmaticallly update content blocks within pages (as a result of url rewriting to libraries not working correctly in the migration).

    I've got this working directly but we really want to do this via a new published version, in case of any problems.

    Can anyone supply an example for doing this?

    Thanks
  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    16 Aug 2017
    29 Jun 2011
    Link to this post
    Hi Justin,

    We have replied to you in the support thread you have opened. You can check my reply there, but for your convenience I'll also paste it below:
    "

    To create revision history of your page you can either CheckIut and then CheckIn the page (which will create a new draft version of the page, newer thatn the published version) or use the version manager and create a version directly. Please find an example of working with the version manager in this forum thread. Concerning the creation of a newer than published draft version, you can use use the below code sample:

    var myPages = App.WorkWith().Pages().LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)

                                                       .Where(pG =>

                                                                    pG.Page != null

                                                                    && pG.Page.Status == ContentLifecycleStatus.Live

                                                                    && pG.Page.Title == "Home")

                                                       .Get()                                                  

                                                       .ToList();

                foreach(var p inmyPages)

                {

                    App.WorkWith().Page(p)

                                        .AsStandardPage()

                                        .CheckOut()

                                        .Do(pag =>

                                                 {

                                                     pag.LastModified = DateTime.UtcNow;

                                                 })

                                                 .CheckIn()

                                        .SaveAndContinue()

                                        .SaveChanges();

                }

    I'm doing this only to my "Home" page for testing purposes, but you can remove the part that's filtering by title and get all pages, the results should be the same. Please do not forget to make a backup of your project files and DB before applying this modifications.


    "

    If there's anything else we can help you with, please let us know. I'll be glad to help.


    Greetings,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    02 Feb 2012
    Link to this post
    Boyan,

    I am struggling a little bit with some code. I hope you can help me. At the moment Sitefinity does nto offer a feature where I can specify how many revisions of a page I want to keep. Therefore, I am trying to implement a mechanism through a WebService where:
    1 - I get a list of pages that have more than lets say 1000 revisions,
    2 - Then for each of those pages, I delete revisions that are older than lets say 6 months.

    The first problem that I am getting is that it is complaining about 'pG' not being declared.
    Dim myPages = App.WorkWith().Pages().LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend).Where(pG >= pG.Page IsNot Nothing And pG.Page.RevisionCount >= 1000).Get().ToList()

    What reference am I missing?

    Many thanks,
    Andrei
  4. Justin
    Justin avatar
    4 posts
    Registered:
    26 May 2011
    03 Feb 2012
    Link to this post
    Looks like a syntax error in your where clause?

    should be Where( pG => pG.Page ....
    instead of Where( pG >= pG.Page ....


  5. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    03 Feb 2012
    Link to this post
    Thanks Justin, I knew that. It automatically changes it round for some reason. Because it does not interpret pG properly, it swaps it round thinking that pG is a number or something.
  6. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    03 Feb 2012
    Link to this post
    Hi, I dont need anymore help here. I took a different approach which seems to be fine. I am doing it via a Custom Module, which seems to have all teh references sorted.
    Many thanks
6 posts, 0 answered