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
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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.
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
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
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
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
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
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
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
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