Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • greengiant83 88 posts 109 karma points
    Jun 28, 2011 @ 06:01
    greengiant83
    0

    How to distinguish between published / saved

    In the backoffice if a document has been saved but not published a little orange star is overlayed its icon in the tree. Via the APIhow can I tell if a document is Saved vs Published?

     

  • Richard Soeteman 4035 posts 12842 karma points MVP
    Jun 28, 2011 @ 08:00
    Richard Soeteman
    0

    Hi,

    You can use the Published property on the Document object.

    Document doc = new Document(id of the document);

    bool published = doc.Published

    Hope the helps you,

    Richard

  • greengiant83 88 posts 109 karma points
    Jun 28, 2011 @ 18:01
    greengiant83
    0

    That does not appear to be what I am looking for.  That appears to indicate if there exists a published version of the document. What I am looking for is if the current doc has a saved version that is newer than the published version.  That is to say I want to know if that little orange star is there or not for this doc.

  • greengiant83 88 posts 109 karma points
    Jun 28, 2011 @ 18:01
    greengiant83
    0

    That does not appear to be what I am looking for.  That appears to indicate if there exists a published version of the document. What I am looking for is if the current doc has a saved version that is newer than the published version.  That is to say I want to know if that little orange star is there or not for this doc.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jun 28, 2011 @ 18:03
    Tom Fulton
    1

    Possibly doc.HasPendingChanges(); might be what you want?

    -Tom

  • greengiant83 88 posts 109 karma points
    Jun 28, 2011 @ 18:08
    greengiant83
    0

    Thank you.  That appears to do the trick.

  • greengiant83 88 posts 109 karma points
    Jun 29, 2011 @ 20:41
    greengiant83
    0

    Having been testing this for a few days now. doc.HasPendingChanges() is not 100% accurate. I looked at the source code for this method and it figures this by comparing the doc's version date to the update date. If they differ by more than half a second it figures there are pending changes.  This is neccesarily the case.  If your server's are running a little slow during publish actions those two timestamps might vary by more than that. In fact during local dev I have frequently that this be the case.

  • Tim 1193 posts 2675 karma points MVP 3x c-trib
    Jul 01, 2011 @ 12:14
    Tim
    0

    @greengiant, you could write a custom method to query the database and check I guess. Not sure of the field names etc, as I don't have the Umbraco Database in front of me, but the basic logic would be to check if the version is the most recent one by selecting the top 1 from the revisions table ordered by date desc, and compare the IDs to see if they're the same?

  • Chris Randall 1 post 21 karma points
    Jul 01, 2011 @ 12:26
    Chris Randall
    0

    Nice example of how Umbraco is constantly being refactored due to the needs of the users.

Please Sign in or register to post replies

Write your reply to:

Draft