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.

Data Model Questions /

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

Versioning Text input


Go to End


3 Posts   927 Views

Avatar
TheBnl

Community Member, 3 Posts

11 April 2015 at 1:11am

Hi All,

I'm currently busy with a project that requires me to save versions of a text input connected to a Member.
How i imagined it is as follows; I have a Member that has a $has_many relation to the DataObject ProjectDescription.
So every time a Member would save his/her project description it would create an altered copy of the previous description (if there is a last one).

The problem i'm having now is how would i go about the creating a copy and saving a new one. Because it is connected to a Member i would first need to get the Current Member and his/her last Description. but then what? Do i populateDefaults with the previous data, then save a new one onBeforeWrite ?

Any help or advice would be much appreciated!
Thanks,
Bram

Avatar
Pyromanik

Community Member, 419 Posts

13 April 2015 at 10:24pm

Edited: 13/04/2015 10:25pm

Hi Bram,

There is an extension already created for this. Unfortunately it is coupled to having staged content also, but it may be able to be applied without stages (so hopefully would just track versions.)

The class you're looking for is Versioned
To see an example of how it works, check the CMS's SiteTree.php (Pages use Versioned to have a draft & live content, along with tracking all changes on save).

Avatar
TheBnl

Community Member, 3 Posts

14 April 2015 at 9:32am

Hi! Thanks for the answer, this was exactly what i as looking for!
I don't need to use the staging but the historical versions is exactly what i needed.