Skip to content

Commit

Permalink
Require DB transaction in Zotero.Collection.prototype.removeItems()
Browse files Browse the repository at this point in the history
For consistency with Zotero.Collection.prototype.addItems()
  • Loading branch information
dstillman committed Feb 3, 2017
1 parent f98de97 commit 7ede523
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
31 changes: 16 additions & 15 deletions chrome/content/zotero/xpcom/data/collection.js
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand All @@ -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
})
}
});


Expand Down
12 changes: 8 additions & 4 deletions chrome/content/zotero/xpcom/itemTreeView.js
Expand Up @@ -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();
});
Expand Down Expand Up @@ -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));
}
}
}
Expand Down

0 comments on commit 7ede523

Please sign in to comment.