commit c442daedcec41a47a232d511053773e887818798
parent 5ec7c97f306f537bdd1b801f116380d337af1085
Author: Dan Stillman <dstillman@zotero.org>
Date: Wed, 13 Sep 2017 01:01:36 -0400
Update collection cache after "Delete collection and items…"
Fixes #1314
Diffstat:
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git 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 descendents = this.getDescendents(false, null, true);
var items = [];
+ var libraryHasTrash = Zotero.Libraries.hasTrash(this.libraryID);
var del = [];
var itemsToUpdate = [];
@@ -586,19 +587,23 @@ Zotero.Collection.prototype._eraseData = Zotero.Promise.coroutine(function* (env
}
// Descendent items
else {
- // Delete items from DB
+ // Trash/delete items
if (env.options.deleteItems) {
del.push(descendents[i].id);
}
- else {
+
+ // If item isn't being removed or is just moving to the trash, mark for update
+ if (!env.options.deleteItems || libraryHasTrash) {
itemsToUpdate.push(descendents[i].id);
}
}
}
if (del.length) {
- if (Zotero.Libraries.hasTrash(this.libraryID)) {
+ if (libraryHasTrash) {
yield this.ChildObjects.trash(del);
- } else {
+ }
+ // If library doesn't have trash, just erase
+ else {
Zotero.debug(Zotero.Libraries.getName(this.libraryID) + " library does not have trash. "
+ this.ChildObjects._ZDO_Objects + " will be erased");
let options = {};
@@ -638,7 +643,7 @@ Zotero.Collection.prototype._eraseData = Zotero.Promise.coroutine(function* (env
env.deletedObjectIDs = collections;
// Update collection cache for descendant items
- if (!env.options.deleteItems) {
+ if (itemsToUpdate.length) {
let deletedCollections = new Set(env.deletedObjectIDs);
itemsToUpdate.forEach(itemID => {
let item = Zotero.Items.get(itemID);
diff --git a/test/tests/collectionTest.js b/test/tests/collectionTest.js
@@ -53,6 +53,14 @@ describe("Zotero.Collection", function() {
yield collection.eraseTx();
assert.lengthOf(item.getCollections(), 0);
});
+
+ it("should clear collection from item cache in deleteItems mode", function* () {
+ var collection = yield createDataObject('collection');
+ var item = yield createDataObject('item', { collections: [collection.id] });
+ assert.lengthOf(item.getCollections(), 1);
+ yield collection.eraseTx({ deleteItems: true });
+ assert.lengthOf(item.getCollections(), 0);
+ });
})
describe("#version", function () {