Create a new page version

Posted by Community Admin on 03-Aug-2018 03:03

Create a new page version

All Replies

Posted by Community Admin on 02-Apr-2011 00:00
Hi all,

I'm trying to rollback to create a new page version by using the API. I'm able to successfully delete a previous version of a page like this:

// Delete version by comment (note)
Change deleteTextChange = versionManager.GetItemVersionHistory(page.Id)
    .Where(ch => ch.Comment == "Removed text")
    .SingleOrDefault();
 
versionManager.DeleteChange(deleteTextChange.Id);
versionManager.SaveChanges();

but I can't get the versionManager.CreateVersion() method working. I keep getting a StackOverflowException. Is there a code sample you can show me of how to rollback to create a new page version in code?

Thanks,
Peter
Posted by Community Admin on 05-Apr-2011 00:00
Hi Peter,

You can use the code below to create  a new version of a page. You should work with the page draft.

               var pageMan = PageManager.GetManager();

                var draft = pageMan.GetDraft<PageDraft>(new Guid(draftId));
                var pageId = draft.ParentPage.Id;
                pageMan.PublishPageDraft(draft, true);
                var versManager = VersionManager.GetManager();
                versManager.CreateVersion(draft, pageId, true);
                pageMan.SaveChanges();
                versManager.SaveChanges();

      

Kind regards,
Ivan Dimitrov
the Telerik team

Posted by Community Admin on 12-Apr-2011 00:00
Hi Ivan,

Thanks for the reply. I've played around with this code but still can't get a Rollback to a page's previous version. I'm trying to mimic the UI feature in Revision History where you can click on a previous published version of the page and then click "Revert to this version". The problem I'm having with the code below is that no draft exists for the version I want to rollback to. Can you show an example of rolling back to a previously published page version?

Thanks,
Peter
Posted by Community Admin on 13-Apr-2011 00:00
Hi Peter,

I sent a reply to your support request, but will post the sample here as well.

string pagedataID = "94fdb149-d317-4b4f-9bba-65c260b5f5dc";
var id = new Guid(pagedataID);
var pageManager = PageManager.GetManager();
var versionManager = VersionManager.GetManager();
 
// get a version ID - this is the version to which you will revert. Note that this creates a new version in the UI
// this works in the same way if you use the UI.
var changeId = versionManager.GetItemVersionHistory(id)[2].Id;
var draft = pageManager.EditPage(id, true);
 
var version = versionManager.GetChanges().Where(u => u.Id == changeId).FirstOrDefault();
if (version != null)
    versionManager.GetSpecificVersion(draft, id, version.Version);
      
pageManager.PublishPageDraft(draft.Id, true);
versionManager.CreateVersion(draft, id, true);
pageManager.SaveChanges();
versionManager.SaveChanges();


Greetings,
Ivan Dimitrov
the Telerik team

Posted by Community Admin on 13-Apr-2011 00:00
Thanks Ivan! That's exactly what I was looking for. I love how much power the versioning/rollback API gives us.
Posted by Community Admin on 16-Dec-2011 00:00
I see the feature to specify how many versions you want or what the life span of a page is has not even been scheduled yet. Meanwhile pages that are frequently amended keep making the database bigger and bigger.
1 - If I wanted to make a solution of my own as a scheduled job in SQL Server Maintenance tasks, which table do I look for to delete items from?
2 - What other things (non-content) like loggs of some kind that I do not need, get saved to the database which I could purge.

Many thanks,
Andrei

Posted by Community Admin on 19-Dec-2011 00:00
Hello Andrei,

Have you tried to shrink the database. By the fault the database is not set to be shrunk. Also making direct changes to the database could cause some issues with the ORM. You should better use the api with some scheduled service that triggers each day or week. We make manual changes only in cases where we need to fix a client's issue but in most cases the problem comes from 1-5 items respectively rows.

All the best,
Ivan Dimitrov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Posted by Community Admin on 19-Dec-2011 00:00
Ivan

Is it worth me waiting though, given that the feature is not even scheduled or not? Also not sure what you meant by: "...but in most cases the problem comes from 1-5 items respectively rows..." Didnt really want to have separate Services but it looks like a must for us.

Many thanks,
Andrei
Posted by Community Admin on 20-Dec-2011 00:00
Hi Andrei,

You could check the size of sf_chunks. This is a table that could generate large amount of data. To clean the orphaned table you can use the script below

delete from sf_chunks where file_id in
(select c.file_id from sf_chunks c left join sf_media_content mc on
c.file_id=mc.file_id where mc.file_id is null)

If the table is quite large( like 1-2 GB) you have to call CREATE TABLE #chunks with constraint on temp_pk_sf_chunks and inster the data from sf_chunks into  into #chunks with a join and disctinct operator and finaly truncate table sf_chunks.

Best wishes,
Ivan Dimitrov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Posted by Community Admin on 20-Dec-2011 00:00
Ivan,

This sounds very familiar. Is it anything to do with this: www.sitefinity.com/.../server-error-when-trying-to-edit-content-block.aspx

Well, I guess that the Service idea is the best so far. I will have to investigate that further. Wil get back to you about help with the Fluent API if I need it.

Many thanks,
Andrei
Posted by Community Admin on 21-Dec-2011 00:00
Hi Andrei,

The other post you are referring to seems to resolve another issues. As for the service with the API, it will not delete the items that currently exist in the table, it will start working once you trigger it.

Best wishes,
Ivan Dimitrov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Posted by Community Admin on 22-Dec-2011 00:00
Ok Ivan, Perhaps I will isolate a copy of the Database and try your suggestion just to see if there are any significant gains. I will let you know how I get on.

Many thanks for all your help.
Andrei
Posted by Community Admin on 22-Dec-2011 00:00
Ok, out of 4,267 rows in sf_chunks, it found 151 rows to delete. I guess its something. However, it looks like the Service option is the only option now. Will keep you posted.

Many thanks again,
Andrei
This thread is closed