Fix syncing of related item removal
This commit is contained in:
parent
5f819b7baa
commit
aa1fc01b31
2 changed files with 42 additions and 3 deletions
|
@ -274,8 +274,13 @@ Zotero.DataObjectUtilities = {
|
||||||
var pred2 = Object.keys(data2);
|
var pred2 = Object.keys(data2);
|
||||||
pred2.sort();
|
pred2.sort();
|
||||||
if (!Zotero.Utilities.arrayEquals(pred1, pred2)) return true;
|
if (!Zotero.Utilities.arrayEquals(pred1, pred2)) return true;
|
||||||
for (let i in pred1) {
|
for (let pred in pred1) {
|
||||||
if (!Zotero.Utilities.arrayEquals(pred1[i], pred2[i])) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -561,7 +566,7 @@ Zotero.DataObjectUtilities = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let pred in data2) {
|
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;
|
if (data1[pred]) continue;
|
||||||
|
|
||||||
let vals = typeof data2[pred] == 'string' ? [data2[pred]] : data2[pred];
|
let vals = typeof data2[pred] == 'string' ? [data2[pred]] : data2[pred];
|
||||||
|
|
|
@ -1316,6 +1316,40 @@ describe("Zotero.Item", function () {
|
||||||
assert.isFalse(json.parentItem);
|
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* () {
|
it("shouldn't clear storage properties from original in .skipStorageProperties mode", function* () {
|
||||||
var item = new Zotero.Item('attachment');
|
var item = new Zotero.Item('attachment');
|
||||||
item.attachmentLinkMode = 'imported_file';
|
item.attachmentLinkMode = 'imported_file';
|
||||||
|
|
Loading…
Reference in a new issue