Skip to content

Commit

Permalink
SitecoreUnicorn#30 - Do not reset fields which are excluded in the fi…
Browse files Browse the repository at this point in the history
…eldFilter
  • Loading branch information
NaibafCH committed Mar 27, 2019
1 parent 752859c commit 9e6a352
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,45 @@ public void Deserialize_IgnoresField_ExcludedWithFieldFilter()
}
}

[Fact]
public void Deserialize_IgnoresField_ExcludedWithFieldFilterNotSerialized()
{
var ignoredFieldId = ID.NewID;
var ignoredSharedFieldId = ID.NewID;

var fieldFilter = Substitute.For<IFieldFilter>();
fieldFilter.Includes(Arg.Any<Guid>()).Returns(true);
fieldFilter.Includes(ignoredFieldId.Guid).Returns(false);
fieldFilter.Includes(ignoredSharedFieldId.Guid).Returns(false);

var deserializer = new DefaultDeserializer(false, Substitute.For<IDefaultDeserializerLogger>(), fieldFilter);
deserializer.ParentDataStore = new SitecoreDataStore(deserializer);

using (var db = new Db())
{
var itemId = ID.NewID;

db.Add(new DbItem("Test Item", itemId)
{
new DbField(ignoredFieldId) { Value = "Test Value", Shared = false },
new DbField(ignoredSharedFieldId) { Value = "Shared Test Value", Shared = true }
});

var itemData = new ProxyItem(new ItemData(db.GetItem(itemId)));

var fields = new List<IItemFieldValue>();
((ProxyItemVersion)itemData.Versions.First()).Fields = fields;
itemData.SharedFields = fields;

deserializer.Deserialize(itemData);

var fromDb = db.GetItem(itemId);

Assert.Equal(fromDb[ignoredFieldId], "Test Value");
Assert.Equal(fromDb[ignoredSharedFieldId], "Shared Test Value");
}
}

protected IDeserializer CreateTestDeserializer(Db db)
{
var fieldFilter = Substitute.For<IFieldFilter>();
Expand Down
8 changes: 6 additions & 2 deletions src/Rainbow.Storage.Sc/Deserialization/DefaultDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ protected virtual void PasteSharedFields(IItemData serializedItemData, Item targ

foreach (Field field in targetItem.Fields)
{
if (field.Shared && !allTargetSharedFields.Contains(field.ID.Guid))
if (field.Shared && !allTargetSharedFields.Contains(field.ID.Guid) && _fieldFilter.Includes(field.ID.Guid))
{
_logger.ResetFieldThatDidNotExistInSerialized(field);

Expand Down Expand Up @@ -472,6 +472,9 @@ protected virtual Item PasteVersion(Item item, IItemVersion serializedVersion, b
// (we do all these checks so we can back out of the edit context and avoid a DB write if we don't need one)
foreach (Field field in languageVersionItem.Fields)
{
// if the field is excluded by the fieldFilter
if (!_fieldFilter.Includes(field.ID.Guid)) continue;

// shared/unversioned fields = ignore, those are handled in their own paste methods
if (field.Shared || field.Unversioned) continue;

Expand Down Expand Up @@ -587,7 +590,8 @@ protected virtual void PasteUnversionedLanguage(Item item, IItemLanguage seriali
foreach (Field field in targetItem.Fields)
{
// field was not serialized. Which means the field is either blank or has its standard value, so let's reset it
if (field.Unversioned && !field.Shared && !allTargetUnversionedFields.Contains(field.ID.Guid))
if (field.Unversioned && !field.Shared && !allTargetUnversionedFields.Contains(field.ID.Guid) &&
_fieldFilter.Includes(field.ID.Guid))
{
_logger.ResetFieldThatDidNotExistInSerialized(field);

Expand Down

0 comments on commit 9e6a352

Please sign in to comment.