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
This commit is contained in:
Dan Stillman 2020-04-13 01:23:20 -04:00
parent c5a4871a6a
commit 617564982c
2 changed files with 27 additions and 1 deletions

View file

@ -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;

View file

@ -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 () {