From 617564982c81962a9ddf819f7e09385ddd91ec51 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 13 Apr 2020 01:23:20 -0400 Subject: [PATCH] Include only related-item relations when duplicating items Don't include linked-object or replaced-item relations. Previously, if you duplicated an item, modified it to represent a different source, and dragged it to another library where you had already copied the original item, the new item wouldn't be transferred. https://forums.zotero.org/discussion/comment/353246/#Comment_353246 --- chrome/content/zotero/xpcom/data/item.js | 18 +++++++++++++++++- test/tests/itemTest.js | 10 ++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 8b1aab7d63..6d33665835 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -4006,7 +4006,23 @@ Zotero.Item.prototype.clone = function (libraryID, options = {}) { if (sameLibrary) { // DEBUG: this will add reverse-only relateds too - newItem.setRelations(this.getRelations()); + let relations = this.getRelations(); + + // Only include certain relations + let predicates = [ + Zotero.Relations.relatedItemPredicate, + ]; + let any = false; + let newRelations = {}; + for (let predicate of predicates) { + if (relations[predicate]) { + newRelations[predicate] = relations[predicate]; + any = true; + } + } + if (any) { + newItem.setRelations(newRelations); + } } return newItem; diff --git a/test/tests/itemTest.js b/test/tests/itemTest.js index 586a710471..c56dc38d57 100644 --- a/test/tests/itemTest.js +++ b/test/tests/itemTest.js @@ -1336,6 +1336,16 @@ describe("Zotero.Item", function () { var newItem = item.clone(); assert.sameDeepMembers(item.getCreators(), newItem.getCreators()); }) + + it("shouldn't copy linked-item relation", async function () { + var group = await getGroup(); + var groupItem = await createDataObject('item', { libraryID: group.libraryID }); + var item = await createDataObject('item'); + await item.addLinkedItem(groupItem); + assert.equal(await item.getLinkedItem(group.libraryID), groupItem); + var newItem = item.clone(); + assert.isEmpty(Object.keys(newItem.toJSON().relations)); + }); }) describe("#moveToLibrary()", function () {