commit 7ede52355dce104f06a7be2c53de6aec5de7dc75
parent f98de97e4da4d76423dddee93c1c1406e9faf599
Author: Dan Stillman <dstillman@zotero.org>
Date: Thu, 2 Feb 2017 18:39:42 -0500
Require DB transaction in Zotero.Collection.prototype.removeItems()
For consistency with Zotero.Collection.prototype.addItems()
Diffstat:
2 files changed, 24 insertions(+), 19 deletions(-)
diff --git a/chrome/content/zotero/xpcom/data/collection.js b/chrome/content/zotero/xpcom/data/collection.js
@@ -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
+ })
+ }
});
diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js
@@ -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));
}
}
}