Skip to content

Commit

Permalink
Automatically use remote version when two items in trash are in conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
dstillman committed Jan 26, 2017
1 parent e234523 commit aec9b2a
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 3 deletions.
9 changes: 6 additions & 3 deletions chrome/content/zotero/xpcom/sync/syncLocal.js
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down
81 changes: 81 additions & 0 deletions test/tests/syncLocalTest.js
Expand Up @@ -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"
},
]
);
});
})


Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit aec9b2a

Please sign in to comment.