Fix "Item collection [n] not found" error after deleting collection
This commit is contained in:
parent
90603c33b4
commit
60b2e16746
|
@ -569,6 +569,7 @@ Zotero.Collection.prototype._eraseData = Zotero.Promise.coroutine(function* (env
|
||||||
var items = [];
|
var items = [];
|
||||||
|
|
||||||
var del = [];
|
var del = [];
|
||||||
|
var itemsToUpdate = [];
|
||||||
for(var i=0, len=descendents.length; i<len; i++) {
|
for(var i=0, len=descendents.length; i<len; i++) {
|
||||||
// Descendent collections
|
// Descendent collections
|
||||||
if (descendents[i].type == 'collection') {
|
if (descendents[i].type == 'collection') {
|
||||||
|
@ -587,6 +588,9 @@ Zotero.Collection.prototype._eraseData = Zotero.Promise.coroutine(function* (env
|
||||||
if (env.options.deleteItems) {
|
if (env.options.deleteItems) {
|
||||||
del.push(descendents[i].id);
|
del.push(descendents[i].id);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
itemsToUpdate.push(descendents[i].id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (del.length) {
|
if (del.length) {
|
||||||
|
@ -629,8 +633,16 @@ Zotero.Collection.prototype._eraseData = Zotero.Promise.coroutine(function* (env
|
||||||
yield Zotero.DB.queryAsync ('DELETE FROM collections WHERE collectionID IN '
|
yield Zotero.DB.queryAsync ('DELETE FROM collections WHERE collectionID IN '
|
||||||
+ '(' + placeholders + ')', collections);
|
+ '(' + placeholders + ')', collections);
|
||||||
|
|
||||||
// TODO: Update member items
|
|
||||||
env.deletedObjectIDs = collections;
|
env.deletedObjectIDs = collections;
|
||||||
|
|
||||||
|
// Update collection cache for descendant items
|
||||||
|
if (!env.options.deleteItems) {
|
||||||
|
let deletedCollections = new Set(env.deletedObjectIDs);
|
||||||
|
itemsToUpdate.forEach(itemID => {
|
||||||
|
let item = Zotero.Items.get(itemID);
|
||||||
|
item._collections = item._collections.filter(c => !deletedCollections.has(c));
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Zotero.Collection.prototype._finalizeErase = Zotero.Promise.coroutine(function* (env) {
|
Zotero.Collection.prototype._finalizeErase = Zotero.Promise.coroutine(function* (env) {
|
||||||
|
|
|
@ -35,7 +35,24 @@ describe("Zotero.Collection", function() {
|
||||||
|
|
||||||
assert.isTrue((yield Zotero.Items.getAsync(item1.id)).deleted);
|
assert.isTrue((yield Zotero.Items.getAsync(item1.id)).deleted);
|
||||||
assert.isTrue((yield Zotero.Items.getAsync(item2.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 () {
|
describe("#version", function () {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user