Jump to:

23007 Posts in 11866 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Version History on Data Objects

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 2448 Views
  • Mo
    Avatar
    Community Member
    485 Posts

    Version History on Data Objects Link to this post

    Just wondering, has anyone done this? If so, how? Do you just have to use the Versioned class? I know how to use that to make changes between Staged and Live, but not more detailed version history.

    Cheers,

    Mo

  • mark_s
    Avatar
    Community Member
    78 Posts

    Re: Version History on Data Objects Link to this post

    Hi.

    You can use the Versioned decorator on any DataObject class. I have done this on a project where the data objects were managed back end. The tricky thing with versioned is always being aware of which state it's in, and requires a degree of control. Versioned has a variety of methods, including allVersions, which gives you history. Check out it's methods.

    Mark

  • Mo
    Avatar
    Community Member
    485 Posts

    Re: Version History on Data Objects Link to this post

    Ooo, cool. I was kind of hoping that this was the case, but wasn't sure.

    Definitely going to be making use of this very shortly, should be interesting .

    How do you go about viewing a full version history of an object in the CMS though? Would you have to use ModelAdmin, or can you link it into a page version history somehow?

    Cheers,

    Mo

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: Version History on Data Objects Link to this post

    With using Versioned you would have to build your own way of displaying history. Or you could also check out the Moderatable module which I believe has nice tools built in to view versions http://open.silverstripe.org/browser/modules/moderation/trunk

  • mark_s
    Avatar
    Community Member
    78 Posts

    Re: Version History on Data Objects Link to this post

    If you want to see version history, you could have a look at what the CMS does, since it shows full version history. Alternatively, you could query xyz_versions yourself, or use methods in the Versioned decorator.

    The Moderation module may be of use, but it's primary purpose is to allow moderation of data objects from the front end, and provides a moderation backend in the CMS. i.e. submitted data objects are kept in draft, and when approved become published, and visible to the front end. It has decorators for both versioned and unversioned database. The versioned variant is not for the faint-hearted

    Mark

  • Mo
    Avatar
    Community Member
    485 Posts

    Re: Version History on Data Objects Link to this post

    Doesn't Versioned::getAllVersions() (or whatever it is called) return a DataObjectSet? If so, it surely wouldn't be too difficult to get a version history of an object?

    I guess it could be a pain to set up "restore" and "compare" functionality though.

    Mo

  • mark_s
    Avatar
    Community Member
    78 Posts

    Re: Version History on Data Objects Link to this post

    Yes, getAllVersions() returns a DataObjectSet of Versioned_Version objects, which I think contains the fields of the decorated data object plus what's in the _versions table. So it would be straightforward to get a history from that. It can be filtered too. I think you'll need to look at the CMS code if you want to do more fancy things like differences etc. It really depends on what you're trying to achieve.

    Mark

  • Tama
    Avatar
    Community Member
    119 Posts

    Re: Version History on Data Objects Link to this post

    Hi Mark

    I'm trying to work out how to put a filtered list of page versions which will appear in the filter when a CMS editor looks at the page.

    AllVersions() looks promising and I've had a look at the documentation: http://api.silverstripe.org/2.4/sapphire/model/Versioned.html#methodallVersions

    I started with this to get an idea of what would get returned:

    class Page_Controller extends ContentController {
       function PageVersions(){
          $PageVersions = $this->AllVersions();
          debug::show($PageVersions);
       }

    But the debug just returns

    Debug (Page_Controller->PageVersions() in line 93 of Page.php)
    DataObjectSet# ViewableData_Debugger
    # ViewableData_Debugger
    # ViewableData_Debugger
    # ViewableData_Debugger
    ...

    Any ideas where I'm going wrong?

    Cheers
    Tama

    2448 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.