Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Nov 04, 2019 @ 14:07
    Ismail Mayat
    0

    Previous versions of content

    In v8 in content saving event I am doing the following:

     var versionId = sender.GetVersionIds(contentItem.Id, 2); //get top versions so current and previous
    
                    if (versionId.Count() == 2)
                    {
                        var versionNew = sender.GetVersion(versionId.First());
                        var versionOld = sender.GetVersion(versionId.Last());
    
                        var currentXml = versionNew.ToXml(_xmlSerializer).GetOuterXml();
                        var previousXml = versionOld.ToXml(_xmlSerializer).GetOuterXml();
    
                        var diff = new XmlDiff(currentXml, previousXml);
    
                        diff.CompareDocuments(new XmlDiffOptions()
                        {
                            TwoWayMatch = true
                        });
    
    
    
                        var diffList = diff.DiffNodeList;
    
                        if (diffList.Any())
                        {
    

    So I have content and I add image to it then save or sometimes save and publish. I would expect the xml diff to pick up differences. It sometimes works and sometimes doesnt.

    Debugging when i look at xml strings there is no difference. The 2 version ids are different but it seems as though the content is the same.

    Save will create a version but does publish create a version as well? Looking at info tab when you publish there is entry for it so does that mean its creating a version?

    Anyone any ideas?

  • Kevin Jump 2310 posts 14695 karma points MVP 7x c-trib
    Nov 04, 2019 @ 14:13
    Kevin Jump
    0

    Hi,

    I have had a little look at this in the past - when you get to the internals for publish, its a save followed by a publish,

    so the save creates a version and then it's published.

    the entries on the tab are in the audit table, so they don't necessarily mean its a different version.

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Nov 04, 2019 @ 14:15
    Ismail Mayat
    0

    Hmm so what about if i tapped into published event, then get latest 3 versions, i can then assume first is current and last is the saved and they should be different if content has been changed?

  • Kevin Jump 2310 posts 14695 karma points MVP 7x c-trib
    Nov 04, 2019 @ 14:20
    Kevin Jump
    0

    it depends a bit on what you want to do,

    if you only need to do it on publish then the theory should be that there are only two versions. (the previous one and the saved on). the published event should fire after the saved event, so they 'should' return the same thing in terms of versions.

    Just a note I have experienced some strange caching issues getting content (i think these are now resolved in v8.2) where getting things by Key didn't necessarily get you the current version of something, but the previous one, so it might be worth doing some checking that that isn't happening here before you pull all your hair out

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Nov 04, 2019 @ 14:29
    Ismail Mayat
    0

    Kevin,

    I need the version before save / publish. Basically I am trying to see what has changed or more specifically if any images have been added or removed, i need to know which images has been added or removed.

    So i am trying to the get 2 versions, do an xml diff and if there are changes then on both versions regex out list of media ids, then get unique list of those ids then reindex just those ids.

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Nov 12, 2019 @ 08:25
    Ismail Mayat
    100

    Here is what i did to fix this:

    var versionId = sender.GetVersionIds(contentItem.Id, noOfVersions); 
    
                    if (versionId.Count()>1)
                    {
                        var versionNew = sender.GetVersion(versionId.First()); // latest published
                        var versionOld = sender.GetVersion(versionId.Last()); //the saved version 
    
                        var currentXml = versionNew.ToXml(_xmlSerializer).GetOuterXml();
                        var previousXml = versionOld.ToXml(_xmlSerializer).GetOuterXml();
    
Please Sign in or register to post replies

Write your reply to:

Draft