More in this section

Forums / Developing with Sitefinity / VersionManager examples

VersionManager examples

14 posts, 0 answered
  1. JohnGassman
    JohnGassman avatar
    18 posts
    Registered:
    03 Nov 2006
    22 Dec 2008
    Link to this post
    Hello,

    Are there any examples available that show the proper usage of the VersionManager? I would like to be able to programmatically access/update/create versions - I am attempting to implement a custom VersioningProvider that alters how items are versioned (and rolled back).

    I have managed to create a new version, but I either end up with a locked version, or I use CommitChanges and my "new" version seems to get removed.

    Thank you!
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    23 Dec 2008
    Link to this post
    Hello d4ddyo,

    Thank you for using our services.

    For instance you could try to inherit the DefaultProvider. Then, you could override the desired methods and implement the alerting functionality. It will be more easy than starting from scratch. Here is a simple example:

    using System; 
    using Telerik.Versioning; 
    using Telerik.Versioning.Data; 
     
    public class CustomVersioningProvider : DefaultProvider 
        public override IVersionItem CreateItem(Guid id) 
        { 
            // implement alert 
            return base.CreateItem(id); 
        } 
     
        public override void RollbackItem(Guid id, System.Globalization.CultureInfo culture, int version) 
        { 
            // implement alert 
            base.RollbackItem(id, culture, version); 
        } 

    Let us know if there is anything else that we can do for you. If it is possible send us some code with comments in it illustrating your logic.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. JGassman
    JGassman avatar
    6 posts
    Registered:
    11 Jul 2006
    28 Dec 2008
    Link to this post
    Ivan,

    Thanks for the reply. I'm not sure what you are referring to as the "alert" in your message. I need to be able to modify the way sitefinity processes a rollback. My client cannot allow revisions of content to be completely deleted, as is done in the current rollback process.

    It seems like it should be fairly straight-forward to create a new version of the content, copying the version that the user want's to roll-back to. Based on the (very limited) API documentation for the VersionManager, I tried this:

            VersionManager versionManager = new VersionManager(); 
            IVersionItem rollbackVersionItem = versionManager.GetItem(ContentItem.ID, null, version); 
            IVersionItem newVersionItem = versionManager.CreateItem(ContentID, rollbackVersionItem.Culture, rollbackVersionItem.Data); 
     
            versionManager.SaveItem(newVersionItem); 
            versionManager.CommitChanges(ContentItem.ID, null); 
     

    I could see a new version being created in the database (in the sf_VersionItem and sf_VrsTxtData tables), but when I call CommitChanges, the new records disappear. If I do *not* call CommitChanges, then the records remain, but they are in a locked state.

    What I thought would be a simple override of the current versioning provider is proving to be frustrating. The advantage to exposing APIs and using providers is that they can be used to extend functionality, but I am finding that the documentation for how to use the API a bit lacking (or worse, incorrect). I admit that I may trying to use the API incorrectly, but that's the point of my frustration - there is no help that I can find that describes how to use it.

    Thanks for any help!

    Regards,
    John


  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    30 Dec 2008
    Link to this post
    Hi JGassman,

    I thought that your were trying to do the following "I am attempting to implement a custom VersioningProvider that alters how items are versioned (and rolled back)."
    However, CommitChanges unlocks the item if locked. I am sending you an example where I use PublishContent.

    ContentManager contentManager = new ContentManager("News"); 
    IContent content = (IContent)contentManager.GetContent(0, 1)[0]; 
    VersionManager versionManager = new VersionManager(); 
    versionManager.RollbackItem(content.ID, null, 2); 
    contentManager.PublishContent(content.ID); 

    I agree that some topics in Sitefinity's documentation are not developed enough, but we make changes on every release and we are trying to improve the articles.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Meister
    Meister avatar
    262 posts
    Registered:
    09 Nov 2007
    02 Jun 2009
    Link to this post
    Hi

    I too would like to do this
    i.e.

    there are 7 versions of the page, if they click rollback on version 6, it actually creates a version 8 which is actually a copy of version 6, but means i dont loose version 7

    that make sense?
    if so, whats the solution, John, did you manage to do this?
    Thanks
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    08 Jun 2009
    Link to this post
    Hello Quade,

    Using the code from my previous post I am not able to reproduce this behavior. The content item is roll backed to the specified version.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. Meister
    Meister avatar
    262 posts
    Registered:
    09 Nov 2007
    08 Jun 2009
    Link to this post
    Thanks Ivan

    Could you ask the team if there is anyway of acheiving this please,
    I have a client complaining that they want this functionality and i'm not sure how to implement it,

    Cheers
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    08 Jun 2009
    Link to this post
    Hello Quade,

    You can use versionManager.GetNewVersion(content.ID, null); This will create a new version of the last version and you will not lose any version of this content items.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  9. Meister
    Meister avatar
    262 posts
    Registered:
    09 Nov 2007
    22 Oct 2009
    Link to this post
    Thanks Ivan
    Sorry to bring this up after a delay, however, i need to sort this out for the client now and making a copy of the last page isn't the functionality the client wants.

    for example:

    If I have the following history
    1
    2
    3
    4 - current verion

    And i want to roll back to version 2, it essentially, creates a copy of version 2, and makes version5:
    1
    2
    3
    4
    5 - current version (copy of version 2)

    Is it possible to do this?
    Thanks

    p.s. JGassman, did you get this working?
  10. JohnGassman
    JohnGassman avatar
    18 posts
    Registered:
    03 Nov 2006
    22 Oct 2009
    Link to this post
    Hello Quade,

    Yes, we did get it working, and it turned out to be fairly simple. You just need to subclass Telerik's default versioning provider, and update web.config (it's early, so hopefully I am not forgetting something). Below are the versioning class code, and the web.config override.

    New VersioningProvider:
    1 namespace SomeNamespace.Versioning.Data { 
    2  
    3     using System; 
    4     using System.Data; 
    5     using System.Configuration; 
    6     using System.Linq; 
    7     using System.Web; 
    8     using System.Web.Security; 
    9     using System.Web.UI; 
    10     using System.Web.UI.HtmlControls; 
    11     using System.Web.UI.WebControls; 
    12     using System.Web.UI.WebControls.WebParts; 
    13     using System.Xml.Linq; 
    14  
    15     using Nolics.ORMapper.Base; 
    16     using Telerik.Versioning; 
    17  
    18     public class VersioningProvider : Telerik.Versioning.Data.DefaultProvider { 
    19  
    20         /// <summary> 
    21         /// This override alters how rollbacks are processed. Instead of deleting all versions after the 
    22         /// rollback version, we'll create a brand new version from the rollback version. 
    23         /// </summary> 
    24         public override void RollbackItem(Guid id, System.Globalization.CultureInfo culture, int version) { 
    25  
    26             // Get the current item. 
    27             IVersionItem currentItem = this.GetItem(id, culture); 
    28  
    29             // If the current item is locked, it was in an abandoned edit state (i.e. it was edited but not 
    30             // saved or cancelled). We'll delete the item here. 
    31             if (currentItem.Locked) { 
    32                 base.DeleteItem(currentItem);                 
    33             } 
    34              
    35             // Fetch the version to roll back 
    36             IVersionItem oldItem = base.GetItem(id, culture, version); 
    37  
    38             // Create a new version. We'll copy the data from the "rollback" version to the new version. 
    39             IVersionItem newItem = base.GetNewVersion(id, culture); 
    40  
    41             Transaction transaction = new Transaction(); 
    42             transaction.Join((IOdbClass)newItem); 
    43  
    44             // Copy the rollback data to the new version 
    45             newItem.Data = oldItem.Data; 
    46  
    47             // Add a comment to the version to indicate that this was created as a result 
    48             // of a rollback. 
    49             newItem.Description = String.Format("Rollback to Version {0}", oldItem.Version); 
    50  
    51             // Unlock and commit the new item. 
    52             newItem.Locked = false
    53              
    54             transaction.Commit(); 
    55         } 
    56     } 
    57  
    58

    web.config changes (note: our VersioningProvider class is in App_Code, hence the "__Code" assembly reference below)
    1 <versioning defaultProvider="Sitefinity"
    2     <providers> 
    3         <clear/> 
    4         <!-- BEGIN: Custom Versioning Provider --> 
    5         <!--<add name="Sitefinity" type="Telerik.Versioning.Data.DefaultProvider, Telerik.Versioning.Data" connectionStringName="DefaultConnection"/>--> 
    6         <add name="Sitefinity" type="SomeNamespace.Versioning.Data.VersioningProvider, __Code" connectionStringName="DefaultConnection"/> 
    7         <!-- END: Custom Versioning Provider --> 
    8     </providers> 
    9 </versioning> 
    10  

    HTH.

    Regards,
    John Gassman
  11. Meister
    Meister avatar
    262 posts
    Registered:
    09 Nov 2007
    22 Oct 2009
    Link to this post
    Thanks John thats great
    i'll give it a go!

    Cheers!
  12. Meister
    Meister avatar
    262 posts
    Registered:
    09 Nov 2007
    05 Nov 2009
    Link to this post

    Hi,

    we created the provider as mentioned and linked it (also tried replacing it) using the web.config in place of versioning provider.
    Once this didn't seem to work, we created a seperate class library project, placed the code there, compiled it and imported the assembly into our sf project, still we were unable to use it and it seemed that our code is not being hit by sf to do version related tasks and it continue to use its built in functionality.

    can you please suggest us reasons for it to not function.

    thanks

  13. Meister
    Meister avatar
    262 posts
    Registered:
    09 Nov 2007
    09 Nov 2009
    Link to this post
    any ideas on a solution please?
  14. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    11 Nov 2009
    Link to this post
    Hello Quade,

    The version manager does not work with pages. It works with content items from modules. This is why it is not working when you hit rollback on a page version. Unfortunately the API does not contain an exposed method that can allow you to make some customizations in order to allow this.

    However we will expose a copy version method for the next SP, which is due for the end of this month. Once this method is exposed I will follow up either with a KB article or a Blog post sampling how to achieve this.

    Regards,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
14 posts, 0 answered