protected virtual void PasteVersions(IItemData serializedItemData, Item targetItem, bool newItemWasCreated, List <TemplateMissingFieldException> softErrors) { Hashtable versionTable = CommonUtils.CreateCIHashtable(); // this version table allows us to detect and remove orphaned versions that are not in the // serialized version, but are in the database version foreach (Item version in targetItem.Versions.GetVersions(true)) { versionTable[version.Uri] = null; } foreach (var syncVersion in serializedItemData.Versions) { var version = PasteVersion(targetItem, syncVersion, newItemWasCreated, softErrors); if (versionTable.ContainsKey(version.Uri)) { versionTable.Remove(version.Uri); } } foreach (ItemUri uri in versionTable.Keys) { var versionToRemove = Database.GetItem(uri); _logger.RemovingOrphanedVersion(versionToRemove); versionToRemove.Versions.RemoveVersion(); } }
protected virtual bool PasteVersions(IItemData serializedItemData, Item targetItem, bool newItemWasCreated, List <TemplateMissingFieldException> softErrors, IFieldValueManipulator fieldValueManipulator) { Hashtable versionTable = CommonUtils.CreateCIHashtable(); // this version table allows us to detect and remove orphaned versions that are not in the // serialized version, but are in the database version foreach (Item version in targetItem.Versions.GetVersions(true)) { versionTable[version.Uri] = null; } bool anythingChanged = false; foreach (var syncVersion in serializedItemData.Versions) { var res = PasteVersion(targetItem, syncVersion, newItemWasCreated, softErrors, fieldValueManipulator); var committed = res.Item1; if (committed) { anythingChanged = true; } var version = res.Item2; if (versionTable.ContainsKey(version.Uri)) { versionTable.Remove(version.Uri); } } foreach (ItemUri uri in versionTable.Keys) { anythingChanged = true; var versionToRemove = Database.GetItem(uri); _logger.RemovingOrphanedVersion(versionToRemove); versionToRemove.Versions.RemoveVersion(); } return(anythingChanged); }