From 60b2e16746f49d7265022d194e561633c17ec743 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 21 Feb 2017 00:38:00 -0500 Subject: [PATCH] Fix "Item collection [n] not found" error after deleting collection --- .../content/zotero/xpcom/data/collection.js | 14 +++++++++++++- test/tests/collectionTest.js | 19 ++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/collection.js b/chrome/content/zotero/xpcom/data/collection.js index 24ff83bd4..b1787d745 100644 --- a/chrome/content/zotero/xpcom/data/collection.js +++ b/chrome/content/zotero/xpcom/data/collection.js @@ -569,6 +569,7 @@ Zotero.Collection.prototype._eraseData = Zotero.Promise.coroutine(function* (env var items = []; var del = []; + var itemsToUpdate = []; for(var i=0, len=descendents.length; i { + let item = Zotero.Items.get(itemID); + item._collections = item._collections.filter(c => !deletedCollections.has(c)); + }); + } }); Zotero.Collection.prototype._finalizeErase = Zotero.Promise.coroutine(function* (env) { diff --git a/test/tests/collectionTest.js b/test/tests/collectionTest.js index bc3c9211d..e8fdb3570 100644 --- a/test/tests/collectionTest.js +++ b/test/tests/collectionTest.js @@ -35,7 +35,24 @@ describe("Zotero.Collection", function() { assert.isTrue((yield Zotero.Items.getAsync(item1.id)).deleted); assert.isTrue((yield Zotero.Items.getAsync(item2.id)).deleted); - }) + }); + + it("should clear collection from item cache", function* () { + var collection = yield createDataObject('collection'); + var item = yield createDataObject('item', { collections: [collection.id] }); + assert.lengthOf(item.getCollections(), 1); + yield collection.eraseTx(); + assert.lengthOf(item.getCollections(), 0); + }); + + it("should clear subcollection from descendent item cache", function* () { + var collection = yield createDataObject('collection'); + var subcollection = yield createDataObject('collection', { parentID: collection.id }); + var item = yield createDataObject('item', { collections: [subcollection.id] }); + assert.lengthOf(item.getCollections(), 1); + yield collection.eraseTx(); + assert.lengthOf(item.getCollections(), 0); + }); }) describe("#version", function () {