Attachment merge: Compare link mode type

Actually fixes #2527.
This commit is contained in:
Abe Jellinek 2022-04-11 09:30:16 -07:00
parent 237bd8f0ce
commit 892c1169c8
2 changed files with 25 additions and 2 deletions

View file

@ -1077,7 +1077,8 @@ Zotero.Items = function() {
continue;
}
if (masterAttachment.attachmentLinkMode !== otherAttachment.attachmentLinkMode) {
if (!((masterAttachment.isImportedAttachment() && otherAttachment.isImportedAttachment())
|| (masterAttachment.isLinkedFileAttachment() && otherAttachment.isLinkedFileAttachment()))) {
Zotero.debug(`Master attachment ${masterAttachment.key} matches ${otherAttachment.key}, `
+ 'but link modes differ - moving');
otherAttachment.parentItemID = item.id;

View file

@ -840,7 +840,29 @@ describe("Zotero.Items", function () {
assert.equal(attachment2.parentItemID, item1.id);
});
it("should not merge attachments with different link modes", async function () {
it("should merge two stored-file attachments with different link modes", async function () {
let file = getTestDataDirectory();
file.append('test.pdf');
let item1 = await createDataObject('item', { setTitle: true });
let attachment1 = await importPDFAttachment(item1);
attachment1.attachmentLinkMode = Zotero.Attachments.LINK_MODE_IMPORTED_URL;
await attachment1.saveTx();
let item2 = item1.clone();
await item2.saveTx();
let attachment2 = await importPDFAttachment(item2);
await Zotero.Items.merge(item1, [item2]);
assert.isFalse(item1.deleted);
assert.isFalse(attachment1.deleted);
assert.equal(item1.numAttachments(true), 1);
assert.isTrue(item2.deleted);
assert.isTrue(attachment2.deleted);
});
it("should not merge attachments with different link mode types", async function () {
let file = getTestDataDirectory();
file.append('test.pdf');