Preserve linked-object and replaced-item relations when merging items
https://groups.google.com/d/msgid/zotero-dev/6f764822-ed7c-46eb-8068-ce9ed1a1538c%40googlegroups.com
Regression from 617564982c
This commit is contained in:
parent
bb220ad0f2
commit
a8c682bf4b
4 changed files with 78 additions and 3 deletions
|
@ -141,7 +141,7 @@ var Zotero_Duplicates_Pane = new function () {
|
|||
}
|
||||
|
||||
_masterItem = item;
|
||||
itembox.item = item.clone(null, { includeCollections: true });
|
||||
itembox.item = item.clone();
|
||||
}
|
||||
|
||||
|
||||
|
@ -149,7 +149,12 @@ var Zotero_Duplicates_Pane = new function () {
|
|||
var itembox = document.getElementById('zotero-duplicates-merge-item-box');
|
||||
Zotero.CollectionTreeCache.clear();
|
||||
// Update master item with any field alternatives from the item box
|
||||
_masterItem.fromJSON(itembox.item.toJSON());
|
||||
var json = _masterItem.toJSON();
|
||||
// Exclude certain properties that are empty in the cloned object, so we don't clobber them
|
||||
const { relations, collections, tags, ...keep } = itembox.item.toJSON();
|
||||
Object.assign(json, keep);
|
||||
|
||||
_masterItem.fromJSON(json);
|
||||
Zotero.Items.merge(_masterItem, _otherItems);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -4624,7 +4624,7 @@ Zotero.Item.prototype.toJSON = function (options = {}) {
|
|||
}
|
||||
|
||||
// Relations
|
||||
obj.relations = this.getRelations()
|
||||
obj.relations = this.getRelations();
|
||||
|
||||
if (obj.accessDate) obj.accessDate = Zotero.Date.sqlToISO8601(obj.accessDate);
|
||||
|
||||
|
|
|
@ -316,4 +316,53 @@ describe("Item pane", function () {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Duplicates Merge pane", function () {
|
||||
// Same as test in itemsTest, but via UI, which makes a copy via toJSON()/fromJSON()
|
||||
it("should transfer merge-tracking relations when merging two pairs into one item", async function () {
|
||||
var item1 = await createDataObject('item', { title: 'A' });
|
||||
var item2 = await createDataObject('item', { title: 'B' });
|
||||
var item3 = await createDataObject('item', { title: 'C' });
|
||||
var item4 = await createDataObject('item', { title: 'D' });
|
||||
|
||||
var uris = [item2, item3, item4].map(item => Zotero.URI.getItemURI(item));
|
||||
|
||||
var p;
|
||||
|
||||
var zp = win.ZoteroPane;
|
||||
await zp.selectItems([item1.id, item2.id]);
|
||||
zp.mergeSelectedItems();
|
||||
p = waitForItemEvent('modify');
|
||||
doc.getElementById('zotero-duplicates-merge-button').click();
|
||||
await p;
|
||||
|
||||
assert.sameMembers(
|
||||
item1.getRelations()[Zotero.Relations.replacedItemPredicate],
|
||||
[uris[0]]
|
||||
);
|
||||
|
||||
await zp.selectItems([item3.id, item4.id]);
|
||||
zp.mergeSelectedItems();
|
||||
p = waitForItemEvent('modify');
|
||||
doc.getElementById('zotero-duplicates-merge-button').click();
|
||||
await p;
|
||||
|
||||
assert.sameMembers(
|
||||
item3.getRelations()[Zotero.Relations.replacedItemPredicate],
|
||||
[uris[2]]
|
||||
);
|
||||
|
||||
await zp.selectItems([item1.id, item3.id]);
|
||||
zp.mergeSelectedItems();
|
||||
p = waitForItemEvent('modify');
|
||||
doc.getElementById('zotero-duplicates-merge-button').click();
|
||||
await p;
|
||||
|
||||
// Remaining item should include all other URIs
|
||||
assert.sameMembers(
|
||||
item1.getRelations()[Zotero.Relations.replacedItemPredicate],
|
||||
uris
|
||||
);
|
||||
});
|
||||
});
|
||||
})
|
||||
|
|
|
@ -291,6 +291,27 @@ describe("Zotero.Items", function () {
|
|||
assert.sameMembers(rels, [item2URI, item3URI]);
|
||||
})
|
||||
|
||||
// Same as test in itemPaneTest, but without the UI
|
||||
it("should transfer merge-tracking relations when merging two pairs into one item", async function () {
|
||||
var item1 = await createDataObject('item', { title: 'A' });
|
||||
var item2 = await createDataObject('item', { title: 'B' });
|
||||
var item3 = await createDataObject('item', { title: 'C' });
|
||||
var item4 = await createDataObject('item', { title: 'D' });
|
||||
|
||||
var uris = [item2, item3, item4].map(item => Zotero.URI.getItemURI(item));
|
||||
|
||||
await Zotero.Items.merge(item1, [item2]);
|
||||
await Zotero.Items.merge(item3, [item4]);
|
||||
|
||||
await Zotero.Items.merge(item1, [item3]);
|
||||
|
||||
// Remaining item should include all other URIs
|
||||
assert.sameMembers(
|
||||
item1.getRelations()[Zotero.Relations.replacedItemPredicate],
|
||||
uris
|
||||
);
|
||||
});
|
||||
|
||||
it("should update relations pointing to replaced item to point to master", function* () {
|
||||
var item1 = yield createDataObject('item');
|
||||
var item1URI = Zotero.URI.getItemURI(item1);
|
||||
|
|
Loading…
Reference in a new issue