Don't merge with a deleted master attachment
This commit is contained in:
parent
142e3b09f8
commit
f91ca9c18a
2 changed files with 22 additions and 2 deletions
|
@ -1044,7 +1044,7 @@ Zotero.Items = function() {
|
|||
let matchingHash = await otherAttachment.attachmentHash;
|
||||
let masterAttachmentID = masterAttachmentHashes.get(matchingHash);
|
||||
|
||||
if (!masterAttachmentID && item.numAttachments(true)) {
|
||||
if (!masterAttachmentID && item.numAttachments()) {
|
||||
// If that didn't work, hash master attachments by the
|
||||
// most common words in their text and check again.
|
||||
if (!hashesIncludeText) {
|
||||
|
@ -1184,7 +1184,7 @@ Zotero.Items = function() {
|
|||
throw new Error('Invalid hash type');
|
||||
}
|
||||
|
||||
let attachments = (await this.getAsync(item.getAttachments(true)))
|
||||
let attachments = (await this.getAsync(item.getAttachments()))
|
||||
.filter(attachment => attachment.isFileAttachment());
|
||||
let hashes = new Map();
|
||||
await Promise.all(attachments.map(async (attachment) => {
|
||||
|
|
|
@ -886,6 +886,26 @@ describe("Zotero.Items", function () {
|
|||
assert.isFalse(attachment2.deleted);
|
||||
assert.equal(attachment2.parentItemID, item1.id);
|
||||
});
|
||||
|
||||
it("should not merge an attachment with a deleted master attachment", async function () {
|
||||
let item1 = await createDataObject('item', { setTitle: true });
|
||||
let attachment1 = await importPDFAttachment(item1);
|
||||
attachment1.deleted = true;
|
||||
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.isTrue(attachment1.deleted);
|
||||
assert.equal(item1.numAttachments(true), 2);
|
||||
assert.isTrue(item2.deleted);
|
||||
assert.isFalse(attachment2.deleted);
|
||||
assert.equal(attachment2.parentItemID, item1.id);
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue