Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Version History on Data Objects


Go to End


9 Posts   4027 Views

Avatar
Mo

Community Member, 541 Posts

2 June 2010 at 10:44pm

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

Avatar
mark_s

Community Member, 78 Posts

3 June 2010 at 10:47pm

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

Avatar
Mo

Community Member, 541 Posts

3 June 2010 at 11:11pm

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

Avatar
Willr

Forum Moderator, 5523 Posts

4 June 2010 at 1:06pm

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

Avatar
mark_s

Community Member, 78 Posts

4 June 2010 at 8:50pm

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

Avatar
Mo

Community Member, 541 Posts

4 June 2010 at 9:10pm

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

Avatar
mark_s

Community Member, 78 Posts

5 June 2010 at 11:41am

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

Avatar
Tama

Community Member, 138 Posts

19 August 2010 at 10:29am

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

Go to Top