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?
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?
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
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.
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();
Previous versions of content
In v8 in content saving event I am doing the following:
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?
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.
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?
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
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.
Here is what i did to fix this:
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.