Assign merge-tracking relations properly when merging >2 items
https://forums.zotero.org/discussion/71459/incorrect-document-refresh-after-three-item-merge
This commit is contained in:
parent
8853f8ca47
commit
3835bc9110
2 changed files with 26 additions and 1 deletions
|
@ -735,6 +735,8 @@ Zotero.Items = function() {
|
|||
|
||||
|
||||
this.merge = function (item, otherItems) {
|
||||
Zotero.debug("Merging items");
|
||||
|
||||
return Zotero.DB.executeTransaction(function* () {
|
||||
var otherItemIDs = [];
|
||||
var itemURI = Zotero.URI.getItemURI(item);
|
||||
|
@ -758,7 +760,10 @@ Zotero.Items = function() {
|
|||
}
|
||||
|
||||
// Add relations to master
|
||||
item.setRelations(otherItem.getRelations());
|
||||
let oldRelations = otherItem.getRelations();
|
||||
for (let pred in oldRelations) {
|
||||
oldRelations[pred].forEach(obj => item.addRelation(pred, obj));
|
||||
}
|
||||
|
||||
// Remove merge-tracking relations from other item, so that there aren't two
|
||||
// subjects for a given deleted object
|
||||
|
|
|
@ -171,6 +171,26 @@ describe("Zotero.Items", function () {
|
|||
assert.equal(rels[0], item2URI);
|
||||
})
|
||||
|
||||
it("should merge three items", async function () {
|
||||
var item1 = await createDataObject('item');
|
||||
var item2 = await createDataObject('item');
|
||||
var item3 = await createDataObject('item');
|
||||
var item2URI = Zotero.URI.getItemURI(item2);
|
||||
var item3URI = Zotero.URI.getItemURI(item3);
|
||||
|
||||
await Zotero.Items.merge(item1, [item2, item3]);
|
||||
|
||||
assert.isFalse(item1.deleted);
|
||||
assert.isTrue(item2.deleted);
|
||||
assert.isTrue(item3.deleted);
|
||||
|
||||
// Check for merge-tracking relation
|
||||
assert.isFalse(item1.hasChanged());
|
||||
var rels = item1.getRelationsByPredicate(Zotero.Relations.replacedItemPredicate);
|
||||
assert.lengthOf(rels, 2);
|
||||
assert.sameMembers(rels, [item2URI, item3URI]);
|
||||
})
|
||||
|
||||
it("should merge two items when servant is linked to an item absent from cache", function* () {
|
||||
// two group libraries
|
||||
var groupOneInfo = yield createGroup({
|
||||
|
|
Loading…
Reference in a new issue