Automatically use remote version when two items in trash are in conflict

This commit is contained in:
Dan Stillman 2017-01-26 18:07:01 -05:00
parent e23452363b
commit aec9b2a531
2 changed files with 87 additions and 3 deletions

View file

@ -1470,8 +1470,10 @@ Zotero.Sync.Data.Local = {
continue;
}
// Automatically apply remote changes for non-items, even if in conflict
if (objectType != 'item') {
// Automatically apply remote changes if both items are in trash and for non-items,
// even if in conflict
if ((objectType == 'item' && currentJSON.deleted && newJSON.deleted)
|| objectType != 'item') {
continue;
}
@ -1515,7 +1517,8 @@ Zotero.Sync.Data.Local = {
}
// Automatically apply remote changes for non-items, even if in conflict
if (objectType != 'item') {
if ((objectType == 'item' && currentJSON.deleted && newJSON.deleted)
|| objectType != 'item') {
changes.push(c2);
continue;
}

View file

@ -1342,6 +1342,44 @@ describe("Zotero.Sync.Data.Local", function() {
]
);
})
it("should automatically use remote version for unresolvable conflicts when both sides are in trash", function () {
var cacheJSON = {
key: "AAAAAAAA",
version: 1234,
title: "Title 1",
dateModified: "2015-05-14 12:34:56"
};
var json1 = {
key: "AAAAAAAA",
version: 1234,
title: "Title 2",
deleted: true,
dateModified: "2015-05-14 14:12:34"
};
var json2 = {
key: "AAAAAAAA",
version: 1235,
title: "Title 3",
deleted: true,
dateModified: "2015-05-14 13:45:12"
};
var ignoreFields = ['dateAdded', 'dateModified'];
var result = Zotero.Sync.Data.Local._reconcileChanges(
'item', cacheJSON, json1, json2, ignoreFields
);
assert.lengthOf(result.changes, 1);
assert.sameDeepMembers(
result.changes,
[
{
field: "title",
op: "modify",
value: "Title 3"
},
]
);
});
})
@ -1865,6 +1903,49 @@ describe("Zotero.Sync.Data.Local", function() {
);
})
it("should automatically use remote version for conflicting fields when both sides are in trash", function () {
var json1 = {
key: "AAAAAAAA",
version: 1234,
title: "Title 1",
pages: 10,
deleted: true,
dateModified: "2015-05-14 14:12:34"
};
var json2 = {
key: "AAAAAAAA",
version: 1235,
title: "Title 2",
place: "New York",
deleted: true,
dateModified: "2015-05-14 13:45:12"
};
var ignoreFields = ['dateAdded', 'dateModified'];
var result = Zotero.Sync.Data.Local._reconcileChangesWithoutCache(
'item', json1, json2, ignoreFields
);
assert.lengthOf(result.changes, 3);
assert.sameDeepMembers(
result.changes,
[
{
field: "title",
op: "modify",
value: "Title 2"
},
{
field: "pages",
op: "delete"
},
{
field: "place",
op: "add",
value: "New York"
}
]
);
});
it("should automatically use local hyphenated ISBN value if only difference", function () {
var json1 = {
key: "AAAAAAAA",