From aec9b2a5311ac6a030287e02a43c7f8caf5acacc Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 26 Jan 2017 18:07:01 -0500 Subject: [PATCH] Automatically use remote version when two items in trash are in conflict --- chrome/content/zotero/xpcom/sync/syncLocal.js | 9 ++- test/tests/syncLocalTest.js | 81 +++++++++++++++++++ 2 files changed, 87 insertions(+), 3 deletions(-) diff --git a/chrome/content/zotero/xpcom/sync/syncLocal.js b/chrome/content/zotero/xpcom/sync/syncLocal.js index f37a10b4e5..3cb3db47c1 100644 --- a/chrome/content/zotero/xpcom/sync/syncLocal.js +++ b/chrome/content/zotero/xpcom/sync/syncLocal.js @@ -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; } diff --git a/test/tests/syncLocalTest.js b/test/tests/syncLocalTest.js index 961bc88be0..085f335568 100644 --- a/test/tests/syncLocalTest.js +++ b/test/tests/syncLocalTest.js @@ -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",