Fix syncing of related item removal

This commit is contained in:
Dan Stillman 2017-05-02 20:15:54 -04:00
parent 5f819b7baa
commit aa1fc01b31
2 changed files with 42 additions and 3 deletions

View file

@ -274,8 +274,13 @@ Zotero.DataObjectUtilities = {
var pred2 = Object.keys(data2);
pred2.sort();
if (!Zotero.Utilities.arrayEquals(pred1, pred2)) return true;
for (let i in pred1) {
if (!Zotero.Utilities.arrayEquals(pred1[i], pred2[i])) {
for (let pred in pred1) {
let vals1 = typeof data1[pred] == 'string' ? [data1[pred]] : data1[pred];
let vals2 = (!data2[pred] || data2[pred] === '')
? []
: typeof data2[pred] == 'string' ? [data2[pred]] : data2[pred];
if (!Zotero.Utilities.arrayEquals(vals1, vals2)) {
return true;
}
}
@ -561,7 +566,7 @@ Zotero.DataObjectUtilities = {
}
}
for (let pred in data2) {
// Property in first object have already been handled
// Property in first object has already been handled
if (data1[pred]) continue;
let vals = typeof data2[pred] == 'string' ? [data2[pred]] : data2[pred];

View file

@ -1316,6 +1316,40 @@ describe("Zotero.Item", function () {
assert.isFalse(json.parentItem);
});
it("should include relations if related item was removed", function* () {
var item1 = yield createDataObject('item');
var item2 = yield createDataObject('item');
var item3 = yield createDataObject('item');
var item4 = yield createDataObject('item');
var relateItems = Zotero.Promise.coroutine(function* (i1, i2) {
yield Zotero.DB.executeTransaction(function* () {
i1.addRelatedItem(i2);
yield i1.save({
skipDateModifiedUpdate: true
});
i2.addRelatedItem(i1);
yield i2.save({
skipDateModifiedUpdate: true
});
});
});
yield relateItems(item1, item2);
yield relateItems(item1, item3);
yield relateItems(item1, item4);
var patchBase = item1.toJSON();
item1.removeRelatedItem(item2);
yield item1.saveTx();
item2.removeRelatedItem(item1);
yield item2.saveTx();
var json = item1.toJSON({ patchBase });
assert.sameMembers(json.relations['dc:relation'], item1.getRelations()['dc:relation']);
});
it("shouldn't clear storage properties from original in .skipStorageProperties mode", function* () {
var item = new Zotero.Item('attachment');
item.attachmentLinkMode = 'imported_file';