Require DB transaction in Zotero.Collection.prototype.removeItems()

For consistency with Zotero.Collection.prototype.addItems()
This commit is contained in:
Dan Stillman 2017-02-02 18:39:42 -05:00
parent f98de97e4d
commit 7ede52355d
2 changed files with 24 additions and 19 deletions

View file

@ -369,6 +369,7 @@ Zotero.Collection.prototype.addItem = function (itemID, options) {
/**
* Add multiple items to the collection in batch
*
* Requires a transaction
* Does not require a separate save()
*
* @param {Number[]} itemIDs
@ -403,6 +404,7 @@ Zotero.Collection.prototype.addItems = Zotero.Promise.coroutine(function* (itemI
/**
* Remove a item from the collection. The item is not deleted from the library.
*
* Requires a transaction
* Does not require a separate save()
*
* @return {Promise}
@ -425,22 +427,21 @@ Zotero.Collection.prototype.removeItems = Zotero.Promise.coroutine(function* (it
var current = this.getChildItems(true);
return Zotero.DB.executeTransaction(function* () {
for (let i=0; i<itemIDs.length; i++) {
let itemID = itemIDs[i];
if (current.indexOf(itemID) == -1) {
Zotero.debug("Item " + itemID + " not a child of collection " + this.id);
continue;
}
let item = yield this.ChildObjects.getAsync(itemID);
item.removeFromCollection(this.id);
yield item.save({
skipDateModifiedUpdate: true
})
Zotero.DB.requireTransaction();
for (let i=0; i<itemIDs.length; i++) {
let itemID = itemIDs[i];
if (current.indexOf(itemID) == -1) {
Zotero.debug("Item " + itemID + " not a child of collection " + this.id);
continue;
}
}.bind(this));
let item = yield this.ChildObjects.getAsync(itemID);
item.removeFromCollection(this.id);
yield item.save({
skipDateModifiedUpdate: true
})
}
});

View file

@ -1883,13 +1883,15 @@ Zotero.ItemTreeView.prototype.deleteSelection = Zotero.Promise.coroutine(functio
collectionTreeRow.ref.deleteItems(ids);
}
else if (collectionTreeRow.isTrash() || collectionTreeRow.isPublications()) {
Zotero.Items.erase(ids);
yield Zotero.Items.eraseTx(ids);
}
else if (collectionTreeRow.isLibrary(true) || force) {
Zotero.Items.trashTx(ids);
yield Zotero.Items.trashTx(ids);
}
else if (collectionTreeRow.isCollection()) {
collectionTreeRow.ref.removeItems(ids);
yield Zotero.DB.executeTransaction(function* () {
yield collectionTreeRow.ref.removeItems(ids);
});
}
//this._treebox.endUpdateBatch();
});
@ -3047,7 +3049,9 @@ Zotero.ItemTreeView.prototype.drop = Zotero.Promise.coroutine(function* (row, or
throw new Error("Drag source must be a collection");
}
if (collectionTreeRow.id != sourceCollectionTreeRow.id) {
yield collectionTreeRow.ref.removeItems(toMove);
yield Zotero.DB.executeTransaction(function* () {
yield collectionTreeRow.ref.removeItems(toMove);
}.bind(this));
}
}
}